我需要使用graphicsmagick
来操作图像。使用graphicsmagick在collectionFS中进行相同的读取和写入流
我FSCollection看起来是这样的:
Images = new FS.Collection("media", {
stores: [
new FS.Store.FileSystem("anything"),
new FS.Store.FileSystem("something")
],
});
我的问题是,该writeStream应该像readStream一样。这不起作用,因为这会导致一个空的结果:
var read = file.createReadStream('anything'),
write = file.createWriteStream('anything');
gm(read)
.crop(100,100,10,10)
.stream()
.on('end',function(){ console.log('done'); })
.on('error',function(err){ console.warn(err); })
.pipe(write, function (error) {
if (error) console.log(error);
else console.log('ok');
});
无法像这样同时读取和写入同一文件;有效地,当你还在读取文件时,你将覆盖部分文件。最好的办法是写入一个单独的文件,然后在完成后重命名它。 –
@ExplosionPills这是有道理的:-)我不熟悉使用流。我怎样才能使用临时文件? – user3848987