mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-29 18:18:50 +00:00
31 lines
835 B
JavaScript
31 lines
835 B
JavaScript
(function() {
|
|
var diskio, fs, progressStream;
|
|
|
|
fs = require('fs');
|
|
|
|
progressStream = require('progress-stream');
|
|
|
|
diskio = require('diskio');
|
|
|
|
exports.name = 'Raspberry Pi';
|
|
|
|
exports.write = function(options, callback) {
|
|
var error, imageFileSize, imageFileStream, progress;
|
|
imageFileSize = fs.statSync(options.image).size;
|
|
if (imageFileSize === 0) {
|
|
error = new Error("Invalid OS image: " + options.image + ". The image is 0 bytes.");
|
|
return callback(error);
|
|
}
|
|
progress = progressStream({
|
|
length: imageFileSize,
|
|
time: 500
|
|
});
|
|
if (!options.quiet) {
|
|
progress.on('progress', options.progress);
|
|
}
|
|
imageFileStream = fs.createReadStream(options.image).pipe(progress);
|
|
return diskio.writeStream(options.device, imageFileStream, callback);
|
|
};
|
|
|
|
}).call(this);
|