Make use of a 512 block aligner

This commit is contained in:
Juan Cruz Viotti 2015-01-28 10:16:01 -04:00
parent db3d4292f4
commit dcebbc0044
2 changed files with 14 additions and 0 deletions

View File

@ -1,6 +1,18 @@
fs = require('fs')
eventStream = require('event-stream')
progressStream = require('progress-stream')
blockAligner = (blockSize) ->
return eventStream.through (chunk) ->
size = chunk.length % blockSize
if size isnt 0
newChunk = new Buffer(chunk.length + (blockSize - size))
chunk.copy(newChunk)
chunk = newChunk
@emit('data', chunk)
exports.writeImage = (devicePath, imagePath, options = {}, callback = _.noop) ->
if not fs.existsSync(imagePath)
@ -25,6 +37,7 @@ exports.writeImage = (devicePath, imagePath, options = {}, callback = _.noop) ->
progress.on('progress', options.onProgress)
imageFile
.pipe(blockAligner(512))
.pipe(progress)
.pipe(deviceFile)

View File

@ -46,6 +46,7 @@
"capitano": "~1.3.0",
"coffee-script": "~1.8.0",
"conf.js": "^0.1.1",
"event-stream": "^3.2.1",
"git-cli": "~0.8.2",
"lodash": "~2.4.1",
"lodash-contrib": "~241.4.14",