Comparing version 2.0.4 to 3.0.0
@@ -7,2 +7,15 @@ # Change Log | ||
## v3.0.0 - 2018-02-23 | ||
* Doc(README): Update examples with new chunk format #41 [Jonas Hermsmeier] | ||
* Feat(blockmap): Move ReadStream.ReadStream -> BlockMap.ReadStream #41 [Jonas Hermsmeier] | ||
* Feat(read-stream): Make ReadStream emit BlockMap.Chunk #41 [Jonas Hermsmeier] | ||
* Feat(lib): Add BlockMap.Range & ReadStream.ReadRange #41 [Jonas Hermsmeier] | ||
* Test(filter-stream): Remove checks for block.address #41 [Jonas Hermsmeier] | ||
* Feat(filter-stream): Emit Chunk objects instead of Buffers #41 [Jonas Hermsmeier] | ||
## v2.0.5 - 2018-02-20 | ||
* Test(filter-stream): Add assertions for bytes read #44 [Jonas Hermsmeier] | ||
## v2.0.4 - 2018-02-16 | ||
@@ -9,0 +22,0 @@ |
@@ -37,3 +37,3 @@ /** | ||
/** @type {Number} block ranges */ | ||
this.ranges = options.ranges || [] | ||
this.ranges = (options.ranges || []).map(BlockMap.Range.from) | ||
@@ -46,2 +46,23 @@ } | ||
/** | ||
* Range class | ||
* @type {Function} | ||
* @ignore - see range.js | ||
*/ | ||
BlockMap.Range = require( './range' ) | ||
/** | ||
* ReadRange class | ||
* @type {Function} | ||
* @ignore - see read-range.js | ||
*/ | ||
BlockMap.ReadRange = require( './read-range' ) | ||
/** | ||
* Chunk object emitted by sparse streams | ||
* @type {Function} | ||
* @ignore - see chunk.js | ||
*/ | ||
BlockMap.Chunk = require( './chunk' ) | ||
/** | ||
* Supported .bmap format versions | ||
@@ -48,0 +69,0 @@ * @type {Array} |
@@ -5,2 +5,3 @@ var stream = require( 'stream' ) | ||
var debug = require( 'debug' )( 'blockmap:filterstream' ) | ||
var BlockMap = require( './blockmap' ) | ||
@@ -93,11 +94,3 @@ /** | ||
return this.blockMap.ranges.map(( range ) => { | ||
return { | ||
checksum: range.checksum, | ||
start: range.start * this.blockSize, | ||
end: (range.end + 1) * this.blockSize, | ||
length: (range.end - range.start + 1) * this.blockSize, | ||
startLBA: range.start, | ||
endLBA: range.end, | ||
offset: 0, | ||
} | ||
return new BlockMap.ReadRange( range, this.blockSize ) | ||
}) | ||
@@ -185,5 +178,3 @@ }, | ||
// Cut the block, and add position & address to it | ||
block = chunk.slice( start, end ) | ||
block.position = range.start + range.offset | ||
block.address = block.position / this.blockSize | ||
block = new BlockMap.Chunk( chunk.slice( start, end ), range.start + range.offset ) | ||
@@ -197,3 +188,3 @@ // Make sure we don't emit buffers not matching | ||
debug( 'chunk:buffer', 'length < block size' ) | ||
this._chunks.push( block ) | ||
this._chunks.push( block.buffer ) | ||
this._bytes += block.length | ||
@@ -213,7 +204,7 @@ this.position += chunk.length - block.length | ||
// Emit the cut block | ||
debug( 'push', block.position, block.address, block ) | ||
debug( 'push', block.position, block.position / this.blockSize, block ) | ||
this.push( block ) | ||
if( this.options.verify ) { | ||
this._hash.update( block ) | ||
this._hash.update( block.buffer ) | ||
} | ||
@@ -220,0 +211,0 @@ |
@@ -55,2 +55,3 @@ var BlockMap = require( './blockmap' ) | ||
var parts = null | ||
var range = null | ||
var ranges = [] | ||
@@ -62,7 +63,8 @@ | ||
parts = getText( node ).trim().split( '-' ) | ||
ranges.push({ | ||
checksum: node.attribs.sha1 || node.attribs.chksum, | ||
start: +parts[0], | ||
end: +( parts[1] || parts[0] ) | ||
}) | ||
range = new BlockMap.Range( | ||
parseInt( parts[0], 10 ), | ||
parseInt( parts[1] || parts[0], 10 ), | ||
node.attribs.sha1 || node.attribs.chksum | ||
) | ||
ranges.push( range ) | ||
} | ||
@@ -69,0 +71,0 @@ } |
@@ -6,2 +6,3 @@ var stream = require( 'stream' ) | ||
var debug = require( 'debug' )( 'blockmap:readstream' ) | ||
var BlockMap = require( './blockmap' ) | ||
@@ -17,2 +18,3 @@ /** | ||
* @param {String} [options.flags='r'] - fs.open() flags | ||
* @param {Boolean} [options.chunkSize=64K] - default chunk buffer size to read/emit | ||
* @param {Boolean} [options.verify=true] - verify range checksums | ||
@@ -26,4 +28,5 @@ * @param {Boolean} [options.autoClose=true] - close the fd on end | ||
if( !(this instanceof ReadStream) ) | ||
if( !(this instanceof ReadStream) ) { | ||
return new ReadStream( filename, blockMap, options ) | ||
} | ||
@@ -35,2 +38,3 @@ if( blockMap == null ) { | ||
options = options || {} | ||
options.objectMode = true | ||
@@ -53,2 +57,4 @@ if( filename == null && options.fd == null ) { | ||
this.blockSize = this.blockMap.blockSize | ||
/** @type {Number} ... */ | ||
this.chunkSize = options.chunkSize || ( 64 * 1024 ) | ||
/** @type {Boolean} Whether or not to verify range checksums */ | ||
@@ -113,5 +119,2 @@ this.verify = options.verify != null ? | ||
get highWaterMark() { return this._readableState.highWaterMark }, | ||
set highWaterMark( value ) { this._readableState.highWaterMark }, | ||
/** | ||
@@ -126,11 +129,11 @@ * Preprocess the `blockMap`'s ranges into byte-ranges | ||
return this.blockMap.ranges.map(( range ) => { | ||
return { | ||
checksum: range.checksum, | ||
start: (range.start * this.blockSize) + this.start, | ||
end: ((range.end + 1) * this.blockSize) + this.start, | ||
length: (range.end - range.start + 1) * this.blockSize, | ||
startLBA: range.start, | ||
endLBA: range.end, | ||
offset: 0, | ||
} | ||
var range = new BlockMap.ReadRange( range, this.blockSize ) | ||
// Account for readstream's start offset | ||
range.start += this.start | ||
range.end += this.start | ||
return range | ||
}).filter(( range ) => { | ||
@@ -180,5 +183,5 @@ return range.end <= (this.end + this.start) | ||
var range = this.currentRange | ||
var length = Math.min( range.length - range.offset, this.highWaterMark ) | ||
var length = Math.min( range.length - range.offset, this.chunkSize ) | ||
var position = range.start + range.offset | ||
var buffer = Buffer.allocUnsafe( length ) | ||
var chunk = new BlockMap.Chunk( Buffer.allocUnsafe( length ), position ) | ||
var offset = 0 | ||
@@ -189,3 +192,3 @@ | ||
fs.read( this.fd, buffer, offset, length, position, ( error, bytesRead ) => { | ||
fs.read( this.fd, chunk.buffer, offset, length, position, ( error, bytesRead ) => { | ||
@@ -204,5 +207,2 @@ if( error == null && bytesRead !== length ) { | ||
buffer.position = position | ||
buffer.address = position / this.blockSize | ||
range.offset += bytesRead | ||
@@ -218,6 +218,6 @@ | ||
if( this.verify ) { | ||
this._hash.update( buffer ) | ||
this._hash.update( chunk.buffer ) | ||
} | ||
this.push( buffer ) | ||
this.push( chunk ) | ||
@@ -224,0 +224,0 @@ }) |
{ | ||
"name": "blockmap", | ||
"version": "2.0.4", | ||
"version": "3.0.0", | ||
"description": "Tizen's block map format", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -89,5 +89,9 @@ # Blockmap | ||
--- | ||
**NOTE:** Regardless of input version, `blockMap.toString()` will always | ||
create a `.bmap` in the format of the latest version (currently `2.0`). | ||
--- | ||
### Block Map Checksum Verification | ||
@@ -106,7 +110,10 @@ | ||
// Disable range checksum verification: | ||
var blockReadStream = new BlockMap.ReadStream( '/path/to/resin-os.img', blockMap, { | ||
var blockReadStream = BlockMap.createReadStream( '/path/to/resin-os.img', blockMap, { | ||
verify: false, | ||
}) | ||
``` | ||
```js | ||
// Same for filter streams: | ||
var filterStream = new BlockMap.FilterStream( blockMap, { | ||
var filterStream = BlockMap.createFilterStream( blockMap, { | ||
verify: false, | ||
@@ -118,2 +125,10 @@ }) | ||
--- | ||
**NOTE:** These examples just use `fs.writeSync()` in `.on('readable')` for brevity; | ||
of course this should be implemented properly in a writable stream, which the readable | ||
side (i.e. the `BlockMap.ReadStream` or `.FilterStream`) is piped to. | ||
--- | ||
Use a parsed block map to read only mapped regions: | ||
@@ -125,10 +140,10 @@ | ||
// The buffer will have two additional properties set; | ||
// 1) buffer.address – it's block address in respect to the .bmap's block size | ||
// 2) buffer.position – the block's offset (or address) in bytes | ||
// The chunk emitted will have two properties set; | ||
// 1) chunk.buffer – the data buffer | ||
// 2) chunk.position – the chunk's offset (or address) in bytes | ||
// Which can then be used to write only those blocks to the target: | ||
blockReadStream.on( 'readable', function() { | ||
var buffer = null | ||
while( buffer = this.read() ) { | ||
fs.writeSync( fd, buffer, 0, buffer.length, buffer.position ) | ||
var chunk = null | ||
while( chunk = this.read() ) { | ||
fs.writeSync( fd, chunk.buffer, 0, chunk.buffer.length, chunk.position ) | ||
} | ||
@@ -153,10 +168,10 @@ }) | ||
// The buffer will have two additional properties set; | ||
// 1) buffer.address – it's block address in respect to the .bmap's block size | ||
// 2) buffer.position – the block's offset (or address) in bytes | ||
// The chunk emitted will have two properties set; | ||
// 1) chunk.buffer – the data buffer | ||
// 2) chunk.position – the chunk's offset (or address) in bytes | ||
// Which can then be used to write only those blocks to the target: | ||
filterStream.on( 'readable', function() { | ||
var buffer = null | ||
while( buffer = this.read() ) { | ||
fs.writeSync( fd, buffer, 0, buffer.length, buffer.position ) | ||
while( chunk = this.read() ) { | ||
fs.writeSync( fd, chunk.buffer, 0, chunk.buffer.length, chunk.position ) | ||
} | ||
@@ -163,0 +178,0 @@ }) |
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
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
41066
13
943
237