mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-01-31 08:25:36 +00:00
Make use of a 512 block aligner
This commit is contained in:
parent
db3d4292f4
commit
dcebbc0044
@ -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)
|
||||
|
||||
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user