-
Notifications
You must be signed in to change notification settings - Fork 106
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
How to pipe stream #112
Comments
bent returns a stream by default, but unlike request it doesn’t instrument the pipe() command to set the method and headers on a subsequent http stream, so you’ll need to do that yourself. |
Could you show me an example on how to do this please?
Would it be possible to add the pipe method in a future relase?
…---
Daniel
On 7 Jul 2020, at 18:47, Mikeal Rogers ***@***.***> wrote:
bent returns a stream by default, but unlike request it doesn’t instrument the pipe() command to set the method and headers on a subsequent http stream, so you’ll need to do that yourself.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Hi @robertsLando take this example : const fs = require('fs')
const { promisify } = require('util')
const stream = require('stream')
const pipeline = promisify(stream.pipeline)
const bent = require('bent')
const main = async () => {
const readable = await bent('https://images.unsplash.com/photo-1595132938692-83ad2c098e47')()
const writable = fs.createWriteStream('./image.jpg')
await pipeline(readable, writable)
}
main() That works for me ! |
Thanks, it works well in ts: import bent from "bent";
import { createWriteStream } from "fs";
import { resolve } from "path";
import { pipeline } from "stream";
import { promisify } from "util";
const pipe = promisify(pipeline);
const URL = "http://***/1.txt";
export const run = async () => {
const readable = (await bent(URL)("")) as NodeJS.ReadableStream;
const writeable = await createWriteStream(resolve(__dirname, "../2.txt"));
await pipe(readable, writeable);
console.log("0");
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm looking for a way to proxy requests using bent. With request it was working like:
The text was updated successfully, but these errors were encountered: