1.2.2 • Published 4 years ago

bmapflash v1.2.2

Weekly downloads
715
License
MIT
Repository
github
Last release
4 years ago

bmapflash

Flash an image using a .bmap file

npm version dependencies Build Status Build status

Installation

Install bmapflash by running:

$ npm install --save bmapflash

Documentation

bmapflash.flashImageToFileDescriptor(imageStream, deviceFileDescriptor, bmapContents, options) ⇒ EventEmitter

Kind: static method of bmapflash
Summary: Flash image to file descriptor
Returns: EventEmitter - event emitter
Access: public

ParamTypeDefaultDescription
imageStreamReadableStreamimage stream
deviceFileDescriptorNumberdevice file descriptor
bmapContentsStringbmap contents
optionsObject{}options
options.bytesToZeroOutFromTheBeginningNumber0bytes to zero out from the beginning

Example

fs.open('/dev/rdisk2', 'rs+', (error, fd) => {
  if (error) {
    throw error;
  }

  fs.readFile('my/image.bmap', {
    encoding: 'utf8'
  }, (error, bmapContents) => {
    if (error) {
      throw error;
    }

    const image = fs.createReadStream('path/to/image.img');

    const flasher = bmapflash.flashImageToFileDescriptor(image, fd, bmapContents);

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

    flasher.on('error', (error) {
      throw error;
    });

    flasher.on('done', () => {
      console.log('Done!');
    });
  });
});

bmapflash.validateFlashedImage(deviceFileDescriptor, bmapContents) ⇒ EventEmitter

This function reads all the mapped blocks as specified by the .bmap file, generates checksums, and compares them to the checksums specified in the .bmap file.

The returned event emitter might emit the following events:

  • done (Object[]): Emitted when all the blocks have been scanned. This event passes as an argument an array of objects containing the ranges that did not pass validation.

  • error (Error): Emitted when an error happened.

  • progress (Object): Emitted regularly, passing an object containing progress state information.

Kind: static method of bmapflash
Summary: Validate flashed image
Returns: EventEmitter - event emitter
Access: public

ParamTypeDescription
deviceFileDescriptorNumberdevice file descriptor
bmapContentsStringbmap contents

Example

fs.open('/dev/rdisk2', 'rs+', (error, fd) => {
  if (error) {
    throw error;
  }

  fs.readFile('my/image.bmap', {
    encoding: 'utf8'
  }, (error, bmapContents) => {
    if (error) {
      throw error;
    }

    const validator = bmapflash.validateFlashedImage(fd, bmapContents);

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

    validator.on('error', (error) {
      throw error;
    });

    validator.on('done', (invalidRanges) => {
      if (invalidRanges.length !== 0) {
        console.log('Validation was not successful');
      }
    });
  });
});

Support

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

Tests

Run the test suite by doing:

$ npm test

Contribute

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

$ npm run lint

License

bmapflash is free software, and may be redistributed under the terms specified in the license.