I have the following code:
var createThumb128 = function(fileObj, readStream, writeStream) {
gm(readStream, fileObj.name()).resize('128', '128').stream().pipe(writeStream);
};
var store = new FS.Store.GridFS("thumbs_128", { transformWrite: createThumb128})
How can I replace the hardcoded 128 size strings with arguments that I pass to the createThumb function?
I assume that I cannot just add the additional parameter since the transformWrite property requires a function with the specific 3 parameter signature.
You can try "Currying" https://en.wikipedia.org/wiki/Currying
var createThumb = function(size) {
return function(fileObj, readStream, writeStream) {
gm(readStream, fileObj.name()).resize(size, size).stream().pipe(writeStream);
};
}
var store = new FS.Store.GridFS("thumbs_128", { transformWrite: createThumb('128')})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With