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

stream() does not like the stream from module got #470

Closed
Borewit opened this issue Jul 22, 2021 · 3 comments
Closed

stream() does not like the stream from module got #470

Borewit opened this issue Jul 22, 2021 · 3 comments
Assignees
Labels

Comments

@Borewit
Copy link
Collaborator

Borewit commented Jul 22, 2021

import got from 'got';
import {fileTypeStream} from 'file-type';

const url = 'https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg';

const stream1 = got.stream(url);
const stream2 = await fileTypeStream(stream1, {sampleSize: 1024});
if (stream2.fileType && stream2.fileType.mime === 'image/jpeg') {
	// stream2 can be used to stream the JPEG image (from the very beginning of the stream)
	console.log('works');
}

Throws an error:

Error: Failed to pipe. The response has been emitted already.
    at Request.pipe (C:\Users\Borewit\code\github\examples\node_modules\got\dist\source\core\index.js:1476:19)
    at Function.pipeline (node:internal/streams/pipeline:284:13)
    at Request.<anonymous> (C:\Users\Borewit\code\github\file-type\core.js:1432:26)
    at Object.onceWrapper (node:events:513:28)
    at Request.emit (node:events:394:28)
    at emitReadable_ (node:internal/streams/readable:571:12)
    at processTicksAndRejections (node:internal/process/task_queues:82:21)
@Borewit
Copy link
Collaborator Author

Borewit commented Jul 24, 2021

I think this issue is caused by got: sindresorhus/got#1803

@SamCB
Copy link

SamCB commented Dec 5, 2021

Seen any progress with this or know any workaround? I've picked up the latest version of got which should have this update, but still getting the error.

@sindresorhus
Copy link
Owner

I just tried with got 12.1, file-type 17.1.1, and Node.js 14.1, and I'm not seeing any error, so I think this was indeed resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants