Skip to content

Instantly share code, notes, and snippets.

@AndyStewart
Last active August 29, 2015 14:08
Show Gist options
  • Save AndyStewart/394f4455dada9bb4eb0d to your computer and use it in GitHub Desktop.
Save AndyStewart/394f4455dada9bb4eb0d to your computer and use it in GitHub Desktop.
Playing with JS Syntax.
function fileResizer(fileRepository, fileStore, renderThumbnail) {
function listen(event) {
event.data.files.forEach(function(id) {
getFileContents(id, renderThumbnailToStore);
});
}
function getFileContents(id, next) {
fileRepository.getById(id, function(err, file) {
fileStore.get(file.contentsId, function(err, stream) {
if (err) {
return next(err);
}
next(err, { id: file.id, filename: file.filename, stream: stream });
});
});
}
function renderThumbnailToStore(err, fileDetails) {
function resize(thumbnail) {
var outputStream = fileStore.stream(thumbnail.size + '_' + fileDetails.id.toString() + '_' + fileDetails.filename);
renderThumbnail({ x: thumbnail.x, y: thumbnail.y, inputStream: fileDetails.stream, outputStream: outputStream });
}
resize({ x: 100, y: 100, size: 'small' });
resize({ x: 250, y: 250, size: 'medium' });
resize({ x: 500, y: 500, size: 'large' });
}
return Object.freeze({ listen: listen });
}
module.exports = fileResizer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment