Skip to content

Fallback for older node versions doesn't accept backpressure from readable stream #349

@Arlen22

Description

@Arlen22

I don't actually know if readable streams support backpressure in this way, but the incoming data stream is not paused and resumed to allow backpressure. According to google, Readable.toWeb applies backpressure properly, so this only applies to the fallback. This would result in older versions reading the entire file into memory quickly and then slowly trickling it out over TCP.

const createStreamBody = (stream) => {
	if (useReadableToWeb) return Readable.toWeb(stream);
	return new ReadableStream({
		start(controller) {
			stream.on("data", (chunk) => {
				controller.enqueue(chunk);
			});
			stream.on("error", (err) => {
				controller.error(err);
			});
			stream.on("end", () => {
				controller.close();
			});
		},
		cancel() {
			stream.destroy();
		}
	});
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions