Node.js nodejs内存缓冲区已同步。管道()
我正在尝试将pdfkit从png js迁移到pngsj2,因为png js不支持交错png。我需要以同步方式加载PNG文件。我试着这样做:Node.js nodejs内存缓冲区已同步。管道(),node.js,stream,buffer,pdfkit,Node.js,Stream,Buffer,Pdfkit,我正在尝试将pdfkit从png js迁移到pngsj2,因为png js不支持交错png。我需要以同步方式加载PNG文件。我试着这样做: var fs = require('fs'), PNG = require('pngjs2').PNG; var stream = require('stream'); var bufferStream = new stream.PassThrough(); var buf = fs.readFileSync('./logs/rid12.png');
var fs = require('fs'),
PNG = require('pngjs2').PNG;
var stream = require('stream');
var bufferStream = new stream.PassThrough();
var buf = fs.readFileSync('./logs/rid12.png');
bufferStream.end(buf);
var png = null;
bufferStream.pipe(new PNG())
.on('parsed', function() {
console.log("here");
png = this;
});
console.log("there",png);
“there”发生在“here”之前,因此png为空。是否可以通过管道将内存缓冲区传输到PNG解析器,这样我就不必创建回调体系结构?无法使异步方法同步 有这样的图书馆可能会伪造它
asyncblock(function(flow) {
var png = null
flow.sync( bufferStream.pipe(new PNG())
.on('parsed', function() {
console.log("here");
png = this;
flow.callback()
})
);
// png not null
});
无法使异步方法同步 有这样的图书馆可能会伪造它
asyncblock(function(flow) {
var png = null
flow.sync( bufferStream.pipe(new PNG())
.on('parsed', function() {
console.log("here");
png = this;
flow.callback()
})
);
// png not null
});
我不这么认为。也许可以调用(newpng())的某个方法,但我不知道是哪一个。我不这么认为。也许可以调用(newpng())的某个方法,但我不知道是哪一个。