Meteor-CollectionFS
Meteor-CollectionFS copied to clipboard
ENOENT Error, stream error?
I'm on OSX, have Imagemagick installed and the code below works, but only sporadically. Often I get the error below and zero byte image files are written to the directory. I've tried installing Graphicsmagick but there is no improvement.
stream.js:94 W20150204-01:15:32.343(-8)? (STDERR) throw er; // Unhandled stream error in pipe. Error: ENOENT, open '/Users/kai/eboydb/.meteor/local/cfs/files/_tempstore/MyPix-HQMnDBjLstPmMxGoY-0.chunk'
function scaleToTargetByInt (width) {
var maxWidth = 216 * 2; // 2x thumbnail size optimized for Retina display
var originalWidth = width;
var scaleInt = Math.floor(maxWidth/originalWidth);
var scaleSize = scaleInt * originalWidth;
return scaleSize;
}
var OriginalsStore = new FS.Store.FileSystem("OriginalPix", {
path: pathToOriginalsFolder,
transformWrite: function (fileObj, readStream, writeStream) {
// read image dimensions and write to metadata
gm(readStream)
.size({bufferStream: true}, FS.Utility.safeCallback(function (err, size) {
if (err) {
// handle the error
} else {
fileObj.update({$set: {'metadata.width': size.width, 'metadata.height': size.height}});
}
}))
// read metadata.width and scale acordingly
.sample(scaleToTargetByInt(fileObj.metadata.width))
.stream()
.pipe(writeStream);
}
});
I have the same problem on Linux. The error prevented my meteor instance from starting up at all, I could only fix it by deleting the offending file from the CollectionFS collection.
Will try to investigate further.
+1
Just to get some idea about your setup. What meteor packages are you using/version. Can you try to use gridfs as store to compare if the problem still exists?
do you have some real code or logging at // handle the error
, is there an error?
I dropped server side scaling (everything is done client-side now), but the project is on GitHub. I think it is the commit from Feb 4th that was the base for the problem. I never managed to solve it though and moved on.
https://github.com/c6y/eboydb/commit/a7cfef364ea564fdefc21ecadfaa9a3b4c087a05
(apologies for the messy code)
Try it like this:
gm(readStream).size({bufferStream: true}, FS.Utility.safeCallback(function (err, size) {
if (err) {
// handle the error
} else {
fileObj.update({$set: {'metadata.width': size.width, 'metadata.height': size.height}});
this.sample(scaleToTargetByInt(size.width)).stream().pipe(writeStream);
}
}))
If this works, please let us know so we can start to put snippets of some of these common situations in the docs.
+1