Comparing version 3.3.0 to 3.4.0
@@ -7,2 +7,6 @@ # Change Log | ||
## v3.4.0 - 2018-05-30 | ||
* Feat(read-stream): Add a generateChecksums option #51 [Alexis Svinartchouk] | ||
## v3.3.0 - 2018-05-30 | ||
@@ -9,0 +13,0 @@ |
@@ -19,2 +19,3 @@ var stream = require( 'stream' ) | ||
* @param {Boolean} [options.verify=true] - verify range checksums | ||
* @param {Boolean} [options.generateChecksums=false] - calculate range checksums and update blockmap | ||
* @param {Boolean} [options.autoClose=true] - close the fd on end | ||
@@ -60,2 +61,10 @@ * @param {Number} [options.start] - byte offset in file to read from | ||
!!options.verify : true | ||
/** @type {Boolean} Whether or not to calculate range checksums and update blockmap */ | ||
this.generateChecksums = options.generateChecksums != null ? | ||
!!options.generateChecksums : false | ||
if (this.verify && this.generateChecksums) { | ||
throw new Error( 'verify and generateChecksums options are mutually exclusive' ) | ||
} | ||
/** @type {BlockMap.Range} Range being currently processed */ | ||
@@ -98,3 +107,3 @@ this.currentRange = null | ||
*/ | ||
this._hash = this.verify ? | ||
this._hash = ( this.verify || this.generateChecksums ) ? | ||
crypto.createHash( this.blockMap.checksumType ) : null | ||
@@ -152,3 +161,3 @@ | ||
var needsVerify = this.verify && | ||
var needsVerify = ( this.verify || this.generateChecksums ) && | ||
this.currentRange != null && | ||
@@ -168,3 +177,3 @@ this.currentRange.offset === this.currentRange.length | ||
if( range.checksum !== digest ) { | ||
if( this.verify && ( range.checksum !== digest ) ) { | ||
error = new Error( `Invalid checksum for range [${range.startLBA},${range.endLBA}], bytes ${range.start}-${range.end}` ) | ||
@@ -176,3 +185,7 @@ error.checksum = digest | ||
this.rangesVerified++ | ||
if( this.generateChecksums ) { | ||
range.range.checksum = digest | ||
} else { | ||
this.rangesVerified++ | ||
} | ||
@@ -220,3 +233,3 @@ }, | ||
// Feed the hash if we're verifying | ||
if( this.verify ) { | ||
if( this.verify || this.generateChecksums ) { | ||
this._hash.update( chunk.buffer ) | ||
@@ -223,0 +236,0 @@ } |
{ | ||
"name": "blockmap", | ||
"version": "3.3.0", | ||
"version": "3.4.0", | ||
"description": "Tizen's block map format", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
43639
978