Comparing version 1.0.0 to 1.1.0
/** | ||
* BlockMap | ||
* @constructor | ||
* @param {Object} options | ||
* @param {Object} [options] | ||
* @param {String} [options.version='2.0'] | ||
* @param {Number} [options.imageSize=0] | ||
* @param {Number} [options.blockSize=4096] | ||
* @param {Number} [options.blockCount=0] | ||
* @param {Number} [options.mappedBlockCount=0] | ||
* @param {String} [options.checksum] | ||
* @param {String} [options.checksumType='sha256'] | ||
* @param {Array} [options.ranges=[]] | ||
* @returns {BlockMap} | ||
@@ -45,5 +53,3 @@ */ | ||
* Parse a .bmap file | ||
* @param {String|Buffer} value | ||
* @param {BlockMap} [blockMap] – BlockMap instance | ||
* @return {BlockMap} | ||
* @ignore - see parse.js | ||
*/ | ||
@@ -54,4 +60,3 @@ BlockMap.parse = require( './parse' ) | ||
* Stringify a block map into .bmap format | ||
* @param {BlockMap} blockMap – BlockMap instance | ||
* @returns {String} xml | ||
* @ignore - see stringify.js | ||
*/ | ||
@@ -62,3 +67,11 @@ BlockMap.stringify = require( './stringify' ) | ||
* Create a new block map | ||
* @param {Object} options | ||
* @param {Object} [options] | ||
* @param {String} [options.version='2.0'] | ||
* @param {Number} [options.imageSize=0] | ||
* @param {Number} [options.blockSize=4096] | ||
* @param {Number} [options.blockCount=0] | ||
* @param {Number} [options.mappedBlockCount=0] | ||
* @param {String} [options.checksum] | ||
* @param {String} [options.checksumType='sha256'] | ||
* @param {Array} [options.ranges=[]] | ||
* @returns {BlockMap} | ||
@@ -73,3 +86,3 @@ */ | ||
* @param {String|Object} data | ||
* @return {BlockMap} | ||
* @returns {BlockMap} | ||
*/ | ||
@@ -89,5 +102,10 @@ BlockMap.fromJSON = function( data ) { | ||
* @param {BlockMap} blockMap - image's blockmap | ||
* @param {Object} options | ||
* @param {String} options.flags - fs.open() flags | ||
* @return {BlockMap.ReadStream} | ||
* @param {Object} [options] - options | ||
* @param {Number} [options.fd=null] - file descriptor | ||
* @param {String} [options.flags='r'] - fs.open() flags | ||
* @param {Boolean} [options.verify=true] - verify range checksums | ||
* @param {Boolean} [options.autoClose=true] - close the fd on end | ||
* @param {Number} [options.start] - byte offset in file to read from | ||
* @param {Number} [options.end] - byte offset in file to stop at | ||
* @returns {BlockMap.ReadStream} stream | ||
*/ | ||
@@ -99,2 +117,13 @@ BlockMap.createReadStream = function( filename, blockMap, options ) { | ||
/** | ||
* Create a FilterStream with a given block map | ||
* @param {BlockMap} blockMap | ||
* @param {Object} [options] | ||
* @param {Boolean} [options.verify=true] - verify range checksums | ||
* @returns {BlockMap.FilterStream} stream | ||
*/ | ||
BlockMap.createFilterStream = function( blockMap, options ) { | ||
return new BlockMap.FilterStream( blockMap, options ) | ||
} | ||
/** | ||
* BlockMap prototype | ||
@@ -112,3 +141,3 @@ * @type {Object} | ||
* @param {Object} [options] - options | ||
* @param {Boolean} [options.verify=true] - options | ||
* @param {Boolean} [options.verify=true] - verify range checksums | ||
* @returns {BlockMap} | ||
@@ -121,2 +150,6 @@ */ | ||
/** | ||
* Stringify the block map into .bmap format | ||
* @returns {String} xml | ||
*/ | ||
toString: function() { | ||
@@ -123,0 +156,0 @@ return BlockMap.stringify( this ) |
@@ -89,3 +89,3 @@ var stream = require( 'stream' ) | ||
* @param {Number} blockAddress | ||
* @return {Boolean} | ||
* @returns {Boolean} | ||
*/ | ||
@@ -130,3 +130,3 @@ _inRange( blockAddress ) { | ||
* @param {Buffer} block | ||
* @return {Boolean} | ||
* @returns {Boolean} | ||
*/ | ||
@@ -133,0 +133,0 @@ _pushBlock( block ) { |
@@ -10,3 +10,3 @@ var BlockMap = require( './blockmap' ) | ||
* @param {Array} nodes | ||
* @return {Object} node | ||
* @returns {Object} node | ||
*/ | ||
@@ -25,3 +25,3 @@ function firstChild( name, nodes ) { | ||
* @param {Object} node | ||
* @return {String} | ||
* @returns {String} | ||
*/ | ||
@@ -40,3 +40,3 @@ function getText( node ){ | ||
* @param {Array} nodes | ||
* @return {String} | ||
* @returns {String} | ||
*/ | ||
@@ -52,3 +52,3 @@ function textContent( name, nodes ) { | ||
* @param {Object} map | ||
* @return {Array} | ||
* @returns {Array} | ||
*/ | ||
@@ -100,4 +100,5 @@ function getRanges( map ) { | ||
* @param {BlockMap} [blockMap] - BlockMap instance to populate | ||
* @param {Objects} [options] - options | ||
* @return {BlockMap} | ||
* @param {Object} [options] - options | ||
* @param {Boolean} [options.verify] - verify range checksums | ||
* @returns {BlockMap} | ||
*/ | ||
@@ -104,0 +105,0 @@ function parse( value, blockMap, options ) { |
@@ -13,4 +13,8 @@ var stream = require( 'stream' ) | ||
* @param {Object} [options] - options | ||
* @param {Number} [options.fd=null] - file descriptor | ||
* @param {String} [options.flags='r'] - fs.open() flags | ||
* @param {Boolean} [options.verify=true] - verify range checksums | ||
* @param {Boolean} [options.autoClose=true] - close the fd on end | ||
* @param {Number} [options.start] - byte offset in file to read from | ||
* @param {Number} [options.end] - byte offset in file to stop at | ||
* @returns {BlockMap.ReadStream} | ||
@@ -23,6 +27,2 @@ */ | ||
if( filename == null ) { | ||
throw new Error( 'Missing filename' ) | ||
} | ||
if( blockMap == null ) { | ||
@@ -35,2 +35,6 @@ throw new Error( 'Missing block map' ) | ||
if( filename == null && options.fd == null ) { | ||
throw new Error( 'Missing filename or file descriptor' ) | ||
} | ||
this.options.verify = this.options.verify != null ? | ||
@@ -41,2 +45,4 @@ !!this.options.verify : true | ||
/** @type {Number} File descriptor */ | ||
this.fd = this.options.fd || null | ||
/** @type {String} File path */ | ||
@@ -62,3 +68,16 @@ this.path = filename | ||
this.position = 0 | ||
/** @type {Number} Position start offset in bytes */ | ||
this.start = this.options.start || 0 | ||
/** @type {Number} End offset in bytes */ | ||
this.end = this.options.end != null ? | ||
this.options.end : Infinity | ||
if( this.start < 0 ) { | ||
throw new Error( 'Start must not be negative' ) | ||
} | ||
if( this.start > this.end ) { | ||
throw new Error( 'Start must be less or equal to end' ) | ||
} | ||
/** | ||
@@ -101,2 +120,7 @@ * Hash stream to calculate range checksums | ||
_close() { | ||
if( !this.options.autoClose ) { | ||
return this.push( null ) | ||
} | ||
fs.close( this.fd, ( error ) => { | ||
@@ -106,5 +130,11 @@ this.fd = null | ||
}) | ||
}, | ||
_open( callback ) { | ||
if( this.fd != null ) { | ||
return callback.call( this ) | ||
} | ||
fs.open( this.path, this.flags, ( error, fd ) => { | ||
@@ -115,2 +145,3 @@ if( error ) return this._onError( error ) | ||
}) | ||
}, | ||
@@ -167,6 +198,11 @@ | ||
this.position = position | ||
this.position = this.start + position | ||
fs.read( this.fd, buffer, 0, length, position, ( error, bytesRead, buffer ) => { | ||
if( this.position >= this.end ) { | ||
this._isReading = false | ||
return this._close() | ||
} | ||
fs.read( this.fd, buffer, 0, length, this.position, ( error, bytesRead, buffer ) => { | ||
if( bytesRead !== length ) { | ||
@@ -225,2 +261,8 @@ return this.emit( 'error', new Error( 'Bytes read mismatch: ' + bytesRead + ' != ' + length ) ) | ||
destroy() { | ||
if( !this.options.autoClose ) { | ||
stream.Readable.prototype.destroy.call( this ) | ||
return | ||
} | ||
fs.close( this.fd, ( error ) => { | ||
@@ -230,2 +272,3 @@ this.fd = null | ||
}) | ||
}, | ||
@@ -232,0 +275,0 @@ |
@@ -9,3 +9,3 @@ var xml = require( 'xml' ) | ||
* @param {BlockMap} blockMap – BlockMap instance | ||
* @return {String} bmap | ||
* @returns {String} bmap | ||
*/ | ||
@@ -27,7 +27,6 @@ function injectChecksum( bmap, blockMap ) { | ||
* @memberOf BlockMap | ||
* @param {BlockMap} blockMap – BlockMap instance | ||
* @param {Object} [options] – options | ||
* @param {BlockMap} blockMap - BlockMap instance | ||
* @returns {String} xml | ||
*/ | ||
function stringify( blockMap, options ) { | ||
function stringify( blockMap ) { | ||
@@ -34,0 +33,0 @@ var ranges = blockMap.ranges.map( function( range ) { |
{ | ||
"name": "blockmap", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Tizen's block map format", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -5,3 +5,4 @@ # Blockmap | ||
[![npm downloads](https://img.shields.io/npm/dm/blockmap.svg?style=flat-square)](https://npmjs.com/package/blockmap) | ||
[![build status](https://img.shields.io/travis/resin-io-modules/blockmap.svg?style=flat-square)](https://travis-ci.org/resin-io-modules/blockmap) | ||
[![build status](https://img.shields.io/travis/resin-io-modules/blockmap/master.svg?style=flat-square&label=linux)](https://travis-ci.org/resin-io-modules/blockmap) | ||
[![build status](https://img.shields.io/appveyor/ci/resin-io/blockmap/master.svg?style=flat-square&label=windows)](https://ci.appveyor.com/project/resin-io/blockmap) | ||
@@ -8,0 +9,0 @@ This module implements [Tizen's block map format](https://source.tizen.org/documentation/reference/bmaptool/introduction), |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30440
10
684
214
1