1.0.2 • Published 9 years ago

diskio v1.0.2

Weekly downloads
5
License
MIT
Repository
github
Last release
9 years ago

diskio

npm version dependencies Build Status Build status

Raw disk I/O that works in all major operating systems.

Notice this module requires running with admin privileges. Use modules such as windosu to provide elevation if you require that feature on Windows.

This module is special as it addresses Windows issues when writing directly to a physical drive.

Windows needs the following quirks before attempting to write data correctly:

  • Erase the Master Boot Record.
  • Rescan drives.

diskio takes care of this for you, and also triggers a rescan after the data was written, so the volume get's mounted by Windows afterwards.

The API is similar to NodeJS's fs module write and read operations so you should be able to be up and running easily.

Example:

var fs = require('fs');
var diskio = require('diskio');
var stream = fs.createReadStream('../path/to/ubuntu.iso');

diskio.writeStream('\\\\.\\PhysicalDrive1', stream, function(error) {
		if (error) throw error;
		console.log('Ubuntu ISO written to \\\\.\\PhysicalDrive1');
});

In order to list available devices, take a look at drivelist.

Installation

Install diskio by running:

$ npm install --save diskio

Documentation

diskio.write(String device, Buffer buffer, Number offset, Number length, Number position, Function callback)

Similar to fs.write.

It accepts a device string, such as /dev/disk1 or \\.\PhysicalDrive1.

The callback gets one argument: (error).

diskio.writeStream(String device, Readable Stream stream, Function callback)

Pipe a readable stream to a device.

It accepts a device string, such as /dev/disk1 or \\.\PhysicalDrive1.

The callback gets one argument: (error).

diskio.read(String device, Buffer buffer, Number offset, Number length, Number position, Function callback)

Similar to fs.read.

It accepts a device string, such as /dev/disk1 or \\.\PhysicalDrive1.

The callback gets two arguments: (error, buffer).

Tests

Run the test suite by doing:

$ gulp test

Contribute

Before submitting a PR, please make sure that you include tests, and that coffeelint runs without any warning:

$ gulp lint

TODO

  • Allow to read a device as a stream.
  • Improve testing in some areas of the code.

Support

If you're having any problem, please raise an issue on GitHub.

License

The project is licensed under the MIT license.