Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StreamCache is not a true ReadStream #957

Closed
romainmenke opened this issue Dec 31, 2020 · 1 comment
Closed

StreamCache is not a true ReadStream #957

romainmenke opened this issue Dec 31, 2020 · 1 comment
Labels
library Relates to an Origami library

Comments

@romainmenke
Copy link
Collaborator

romainmenke commented Dec 31, 2020

StreamCache does not seem to implement ReadStream correctly.
When used together with merge2 it all seems to work, but when trying to use it as a ReadStream directly, no data|end|... events are ever triggered.

https://github.com/Financial-Times/polyfill-library/blob/b0c8a8582dc164af25e834fc034e2db27c935516/lib/sources.js#L83

https://github.com/felixge/node-stream-cache/blob/master/lib/StreamCache.js

I ended up using this code to be able to read data from StreamCache without merge2.

type StreamCache = {
	pipe: (dest: StreamCacheDestination) => void
}

type StreamCacheDestination = {
	write: (chunk: Buffer) => void,
	end: () => void 
}

async function streamToString(stream: StreamCache) {
	return new Promise<string>((resolve) => {
		let out = '';
		stream.pipe({
			write: (chunk: Buffer) => {
				out += chunk.toString("utf-8");
			},
			end: () => {
				resolve(out);
			},
		});
	});
}

Would it be possible to return a true ReadStream from streamPolyfillSource on a next major release? (I think this is a breaking change).

For now the jsdoc type signature could be updated.

@origamiserviceuser origamiserviceuser added this to incoming in Origami ✨ Dec 31, 2020
@github-actions github-actions bot added the library Relates to an Origami library label Dec 31, 2020
@romainmenke romainmenke changed the title StreamCache is not a true ReadStream StreamCache is not a true ReadStream Dec 31, 2020
@JakeChampion
Copy link
Owner

Would it be possible to return a true ReadStream from streamPolyfillSource on a next major release? (I think this is a breaking change).

Yes, we can do that, if you are able to implement this change I'd be happy to review and release it.

romainmenke added a commit to romainmenke/polyfill-library that referenced this issue Jan 18, 2021
romainmenke added a commit to romainmenke/polyfill-library that referenced this issue Jan 18, 2021
JakeChampion added a commit to romainmenke/polyfill-library that referenced this issue Feb 24, 2021
…-read-stream--considerate-english-cocker-spaniel-1e4b136008
JakeChampion added a commit to romainmenke/polyfill-library that referenced this issue May 24, 2021
…-read-stream--considerate-english-cocker-spaniel-1e4b136008
JakeChampion added a commit to romainmenke/polyfill-library that referenced this issue Jul 12, 2021
…-read-stream--considerate-english-cocker-spaniel-1e4b136008
Origami ✨ automation moved this from incoming to complete Jul 12, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 9, 2022
@robertboulton robertboulton removed this from Done in Origami ✨ Jul 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
library Relates to an Origami library
Projects
None yet
Development

No branches or pull requests

2 participants