Last active
August 29, 2015 14:08
-
-
Save AndyStewart/394f4455dada9bb4eb0d to your computer and use it in GitHub Desktop.
Playing with JS Syntax.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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