简体   繁体   English

我如何使用“ stream.pipe(fs.createWriteStream())”

[英]How do I use “stream.pipe(fs.createWriteStream())”

How do I use stream.pipe? 如何使用stream.pipe?

I'm running a function that outputs: 我正在运行一个输出的函数:

const fs = require('fs');
const screenshot = require('screenshot-stream');
const stream = screenshot('http://google.com', '1024x768');
stream.pipe(fs.createWriteStream('picture.png'));

My next step is taking that picture (picture.png) and assigning it here: 我的下一步是拍摄照片(picture.png)并在此处分配:

var content = fs.readFileSync('/path/to/img')

In other words, what is the path to the image so I can upload it? 换句话说,要上传图片的路径是什么?

Lets say, Your project directory name is "PROJECT", And you executed this file from the root directory of your project, Then the PICTURE.png file will be created in the root directory. 假设,您的项目目录名称为“ PROJECT”,并且您从项目的根目录执行了此文件,然后将在根目录中创建PICTURE.png文件。

And the path to that file'll be __dirname + "/PICTURE.png" if you are still in the root directory of your project. 如果您仍在项目的根目录中,则该文件的路径将为__dirname + "/PICTURE.png"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以在fs.createWriteStream中使用forEach吗? - Can I use forEach within fs.createWriteStream? Stream 使用 Fetch API 和 fs.createWriteStream 响应文件 - Stream response to file using Fetch API and fs.createWriteStream 未捕获的TypeError:fs.​​createWriteStream不是函数 - Uncaught TypeError: fs.createWriteStream is not a function 类型错误:fs.createWriteStream 不是 Node 中的 function - TypeError: fs.createWriteStream is not a function in Node 如何确保fs.createWriteStream在函数继续执行之前完成; 仅保存一部分图像 - How to make sure fs.createWriteStream finishes before function continues; only fraction of image being saved Node.js:如何使用fs.createWriteStream创建具有755权限的文件 - Node.js: How to create file with 755 permissions with fs.createWriteStream ExcelJS writeFile 不起作用:Uncaught TypeError: fs.createWriteStream is not a function - ExcelJS writeFile not working: Uncaught TypeError: fs.createWriteStream is not a function 使用fs.createWriteStream在Node.js中写入大文件 - Writing large file in Nodejs using fs.createWriteStream 是否可以使用 fs.createWriteStream 在文件中间写入文本? (或一般在nodejs中) - Is it possible to write text in the middle of a file with fs.createWriteStream ? (or in nodejs in general) 自动关闭“fs.createWriteStream()”以避免潜在的 memory 泄漏 - Auto close of “fs.createWriteStream()” to avoid potential memory leak
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM