在“sharp”上找到:"^0.26.0“
由于某些原因,此无法工作。
const readableStream = new stream.Readable({
objectMode: true,
read() {}
})
class FileSwitch extends stream.Writable {
constructor(options, folder) {
super(options)
this.i = 0
}
_write(chunk, encoding, next) {
console.log(this.i)
this.i++
next()
}
}
var png = sharp().png()
var fileswitch = new FileSwitch();
readableStream.pipe(png).pipe(fileswitch)无输出
然而,出于某种原因,这确实有效:
const readableStream = new stream.Readable({
objectMode: true,
read() {}
})
class FileSwitch extends stream.Writable {
constructor(options, folder) {
super(options)
this.i = 0
}
_write(chunk, encoding, next) {
console.log(this.i)
this.i++
next()
}
}
var png = sharp().png()
var fileswitch = new FileSwitch();
readableStream.pipe(png.pipe(fileswitch))>>> 0
>>> 1
>>> 2使用setInterval()将可读流按1秒间隔推送新的字符串数据块。
难道我没有把一个功能暴露给一个可写的流,让它变得尖锐吗?文档说,这个设置应该可以工作:)
更新
添加了来自@Matt评论的建议。
const readableStream = new stream.Readable({
objectMode: true,
read() {}
})
class FileSwitch extends stream.Writable {
constructor(options, folder) {
super(options)
this.i = 0
}
_write(chunk, encoding, next) {
console.log(this.i)
this.i++
next()
}
}
readableStream.on('error', listener => {
console.log(listener)
})
readableStream.on('warning', listener => {
console.log(listener)
})
var png = sharp().png()
var fileswitch = new FileSwitch();
readableStream.pipe(png).pipe(fileswitch)无输出
发布于 2020-09-03 15:57:30
被推送到readableStream的数据块不是用于sharp转换为png的有效图像格式。将错误事件侦听器添加到png转换器显示正确的错误。
https://stackoverflow.com/questions/63716286
复制相似问题