Giter Club home page Giter Club logo

etcher-image-write's Introduction

etcher-image-write

The cross-platform way to stream an OS image to a device

npm version dependencies Build Status Build status

Installation

Install etcher-image-write by running:

$ npm install --save etcher-image-write

Documentation

imageWrite.write(drive, image, options) โ‡’ EventEmitter

NOTICE: You might need to run this function as sudo/administrator to avoid permission issues.

We recommend passing file descriptors opened with rs+ flags.

The returned EventEmitter instance emits the following events:

  • progress: A progress event that passes a state object of the form:
{
  type: 'write' // possible values: 'write', 'check'.
  percentage: 9.05,
  transferred: 949624,
  length: 10485760,
  remaining: 9536136,
  eta: 10,
  runtime: 0,
  delta: 295396,
  speed: 949624
}
  • error: An error event.
  • done: An event emitted with a boolean success value.

Enabling the check option is useful to ensure the image was successfully written to the device. This is checked by calculating and comparing checksums from both the original image and the data written to the device.

The transform option is used to handle cases like decompression of an image on the fly. The stream is piped through this transform stream after the progress stream and before any writing and alignment.

This allows the progress to be accurately displayed even when the client doesn't know the final uncompressed size.

For example, to handle writing a compressed file, you pass the compressed stream to .write(), pass the compressed stream size, and a transform stream to decompress the file.

Kind: static method of imageWrite
Summary: Write a readable stream to a device
Returns: EventEmitter - emitter
Access: public

Param Type Default Description
drive Object drive
drive.device String drive device
drive.size Number drive size
drive.fd Number drive file descriptor
image Object image
image.stream ReadStream image readable stream
image.size Number image stream size
options Object options
[options.transform] TransformStream transform stream
[options.check] Boolean false enable write check
[options.bmap] String bmap file contents
[options.bytesToZeroOutFromTheBeginning] Number bytes to zero out from the beginning (bmap only)

Example

var emitter = imageWrite.write({
  fd: fs.openSync('/dev/rdisk2', 'rs+'), // '\\\\.\\PHYSICALDRIVE1' in Windows, for example.
  device: '/dev/rdisk2',
  size: 2014314496
}, {
  stream: fs.createReadStream('my/image'),
  size: fs.statSync('my/image').size
}, {
  check: true
});

emitter.on('progress', (state) => {
  console.log(state);
});

emitter.on('error', (error) => {
  console.error(error);
});

emitter.on('done', (results) => {
  console.log('Success!');
});

Errors

The errors we emit can be identified by their code and type properties.

Consult this file for a list of defined errors.

Support

If you're having any problem, please raise an issue on GitHub and the Resin.io team will be happy to help.

Tests

To run the full test suite (Node & Electron), you'll need to have Electron installed either globally or locally in the repository (npm install [--global] electron).

Run the test suite by doing:

$ npm test

To run only the Node or Electron tests, respectively:

$ npm run test-node # OR
$ npm run test-electron

Contribute

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

$ npm run lint

License

etcher-image-write is free software, and may be redistributed under the terms specified in the license.

etcher-image-write's People

Contributors

balena-ci avatar jhermsmeier avatar jviotti avatar lurch avatar zvin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.