Created
January 28, 2015 13:08
-
-
Save petrosagg/a7e4a43bb342b1bd51b1 to your computer and use it in GitHub Desktop.
Windows sd write test
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
| wincmd = require('node-windows'); | |
| fs = require('fs'); | |
| es = require('event-stream'); | |
| image = fs.createReadStream('image.jpg') | |
| drive = fs.createWriteStream('\\\\.\\PhysicalDrive2', {flags: 'r+'}); | |
| drive.on('error', function (e) { | |
| console.log('Got error', e); | |
| if (e.code === 'EPERM') { | |
| wincmd.elevate('node index.js', {}, function () { | |
| console.log('done'); | |
| }); | |
| } | |
| }); | |
| blockAligner = function (blockSize) { | |
| return es.through(function (chunk) { | |
| var foo = chunk.length % blockSize | |
| if (foo !== 0) { | |
| newChunk = new Buffer(chunk.length + (blockSize - foo)); | |
| chunk.copy(newChunk) | |
| chunk = newChunk | |
| } | |
| console.log("Got chunk with length", chunk.length); | |
| this.emit('data', chunk); | |
| }); | |
| }; | |
| image.pipe(blockAligner(512)).pipe(drive); | |
| //buf = new Buffer(1000) | |
| //buf.fill(50) | |
| //drive.write(buf) | |
| //fs.readSync(drive, buf, 0, 512, null) | |
| //console.log(buf) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment