最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to pipe to a file (NodeJS) - Stack Overflow

programmeradmin1浏览0评论

I have created some image data which I've obtained from pixels. Anyway, now I would like to write a file using save-pixels, but the docs only give

var savePixels = require("save-pixels")
...
savePixels(pixels, "png").pipe(process.stdout)

How to rewrite this such that it writes it to a file with a specific name ?

I have created some image data which I've obtained from pixels. Anyway, now I would like to write a file using save-pixels, but the docs only give

var savePixels = require("save-pixels")
...
savePixels(pixels, "png").pipe(process.stdout)

How to rewrite this such that it writes it to a file with a specific name ?

Share Improve this question asked Mar 1, 2016 at 17:11 Jeanluca ScaljeriJeanluca Scaljeri 29.1k66 gold badges231 silver badges379 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 40

Use the file system module included with node. Something like this:

var fs = require("fs");
var savePixels = require("save-pixels");
var myFile = fs.createWriteStream("myOutput.txt");
...
savePixels(pixels, "png").pipe(myFile);
发布评论

评论列表(0)

  1. 暂无评论