Comparing version 4.0.0-typescript-0ea0a4837bfc224c2663be2c9d3f628144385674 to 4.0.0-typescript-cb9fb56e115cb6b7fe5825d8eba9b5080c741e9f
@@ -9,2 +9,4 @@ # Change Log | ||
* Don't test on node 4 [Alexis Svinartchouk] | ||
* Replace jsdoc with typedoc [Alexis Svinartchouk] | ||
* Change licence MIT -> Apache [Alexis Svinartchouk] | ||
@@ -11,0 +13,0 @@ * Add licence in each ts file [Alexis Svinartchouk] |
@@ -42,16 +42,2 @@ /** | ||
} | ||
/** | ||
* BlockMap | ||
* @constructor | ||
* @param {Object} [options] | ||
* @param {String} [options.version='2.0'] | ||
* @param {Number} [options.imageSize=0] | ||
* @param {Number} [options.blockSize=4096] | ||
* @param {Number} [options.blocksCount=0] | ||
* @param {Number} [options.mappedBlocksCount=0] | ||
* @param {String} [options.checksum] | ||
* @param {String} [options.checksumType='sha256'] | ||
* @param {Array} [options.ranges=[]] | ||
* @returns {BlockMap} | ||
*/ | ||
export declare class BlockMap { | ||
@@ -58,0 +44,0 @@ /** Supported .bmap format versions */ |
@@ -23,19 +23,5 @@ "use strict"; | ||
const range_1 = require("./range"); | ||
function xml2(tag, text) { | ||
function xmlTag(tag, text) { | ||
return xml_js_1.js2xml({ [tag]: { _text: text } }, { compact: true }); | ||
} | ||
/** | ||
* BlockMap | ||
* @constructor | ||
* @param {Object} [options] | ||
* @param {String} [options.version='2.0'] | ||
* @param {Number} [options.imageSize=0] | ||
* @param {Number} [options.blockSize=4096] | ||
* @param {Number} [options.blocksCount=0] | ||
* @param {Number} [options.mappedBlocksCount=0] | ||
* @param {String} [options.checksum] | ||
* @param {String} [options.checksumType='sha256'] | ||
* @param {Array} [options.ranges=[]] | ||
* @returns {BlockMap} | ||
*/ | ||
class BlockMap { | ||
@@ -57,8 +43,8 @@ constructor(options = {}) { | ||
const checksum = this.checksum || ''; | ||
const zerofill = xml2('BmapFileChecksum', checksum.replace(/./g, '0')); | ||
const value = bmap.replace(xml2('BmapFileChecksum', checksum), zerofill); | ||
const zerofill = xmlTag('BmapFileChecksum', checksum.replace(/./g, '0')); | ||
const value = bmap.replace(xmlTag('BmapFileChecksum', checksum), zerofill); | ||
const digest = crypto_1.createHash(this.checksumType) | ||
.update(value) | ||
.digest('hex'); | ||
return value.replace(zerofill, xml2('BmapFileChecksum', digest)); | ||
return value.replace(zerofill, xmlTag('BmapFileChecksum', digest)); | ||
} | ||
@@ -65,0 +51,0 @@ /** Create a block map from its JSON representation */ |
@@ -24,3 +24,3 @@ /** | ||
function xml2(tag: string, text: string): string { | ||
function xmlTag(tag: string, text: string): string { | ||
return js2xml({ [tag]: { _text: text } }, { compact: true }); | ||
@@ -54,16 +54,2 @@ } | ||
/** | ||
* BlockMap | ||
* @constructor | ||
* @param {Object} [options] | ||
* @param {String} [options.version='2.0'] | ||
* @param {Number} [options.imageSize=0] | ||
* @param {Number} [options.blockSize=4096] | ||
* @param {Number} [options.blocksCount=0] | ||
* @param {Number} [options.mappedBlocksCount=0] | ||
* @param {String} [options.checksum] | ||
* @param {String} [options.checksumType='sha256'] | ||
* @param {Array} [options.ranges=[]] | ||
* @returns {BlockMap} | ||
*/ | ||
export class BlockMap { | ||
@@ -97,8 +83,8 @@ /** Supported .bmap format versions */ | ||
const checksum = this.checksum || ''; | ||
const zerofill = xml2('BmapFileChecksum', checksum.replace(/./g, '0')); | ||
const value = bmap.replace(xml2('BmapFileChecksum', checksum), zerofill); | ||
const zerofill = xmlTag('BmapFileChecksum', checksum.replace(/./g, '0')); | ||
const value = bmap.replace(xmlTag('BmapFileChecksum', checksum), zerofill); | ||
const digest = createHash(this.checksumType) | ||
.update(value) | ||
.digest('hex'); | ||
return value.replace(zerofill, xml2('BmapFileChecksum', digest)); | ||
return value.replace(zerofill, xmlTag('BmapFileChecksum', digest)); | ||
} | ||
@@ -105,0 +91,0 @@ |
{ | ||
"name": "blockmap", | ||
"version": "4.0.0-typescript-0ea0a4837bfc224c2663be2c9d3f628144385674", | ||
"version": "4.0.0-typescript-cb9fb56e115cb6b7fe5825d8eba9b5080c741e9f", | ||
"description": "Tizen's block map format", | ||
@@ -26,6 +26,7 @@ "license": "MIT", | ||
"@types/xml": "^1.0.3", | ||
"jsdoc-to-markdown": "^4.0.1", | ||
"mocha": "^6.0.2", | ||
"resin-lint": "^3.0.1", | ||
"ts-node": "^8.0.3", | ||
"typedoc": "^0.14.2", | ||
"typedoc-plugin-markdown": "^1.1.27", | ||
"typescript": "^3.3.4000" | ||
@@ -47,5 +48,5 @@ }, | ||
"benchmark": "ts-node benchmark/blockmap.ts", | ||
"doc": "jsdoc2md 'js/**/*.js' --separators --param-list-format list > doc/README.md", | ||
"doc": "typedoc --readme none --theme markdown --mode file --out doc lib/index.ts", | ||
"prepublishOnly": "npm run lint && npm run test && npm run benchmark && npm run build && npm run doc" | ||
} | ||
} |
@@ -24,3 +24,3 @@ # Blockmap | ||
```js | ||
var BlockMap = require( 'blockmap' ) | ||
const { BlockMap } = require('blockmap') | ||
``` | ||
@@ -31,3 +31,3 @@ | ||
``` | ||
var blockMap = BlockMap.parse( xml ) | ||
const blockMap = BlockMap.parse(xml) | ||
``` | ||
@@ -67,4 +67,4 @@ | ||
```js | ||
var blockMap = BlockMap.parse( value ) | ||
var xml = blockMap.toString() | ||
const blockMap = BlockMap.parse(value) | ||
const xml = blockMap.toString() | ||
``` | ||
@@ -103,21 +103,19 @@ | ||
will be verified when parsing or streaming. If you need to disable verification, | ||
pass `verify: false` in the options: | ||
pass `false` as `verify` parameter. | ||
```js | ||
// Disable verification of the bmap file checksum: | ||
var blockMap = BlockMap.parse( bmap, { verify: false }) | ||
const blockMap = BlockMap.parse(bmap, false) | ||
``` | ||
```js | ||
const { ReadStream } = require('blockmap') | ||
// Disable range checksum verification: | ||
var blockReadStream = BlockMap.createReadStream( '/path/to/resin-os.img', blockMap, { | ||
verify: false, | ||
}) | ||
const blockReadStream = new ReadStream(fileDescriptor, blockMap, false) | ||
``` | ||
```js | ||
const { FilterStream } = require('blockmap') | ||
// Same for filter streams: | ||
var filterStream = BlockMap.createFilterStream( blockMap, { | ||
verify: false, | ||
}) | ||
const filterStream = new FilterStream(blockMap, false) | ||
``` | ||
@@ -131,3 +129,3 @@ | ||
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. | ||
side (i.e. the `ReadStream` or `FilterStream`) is piped to. | ||
@@ -139,4 +137,4 @@ --- | ||
```js | ||
var blockMap = BlockMap.parse( fs.readFileSync( '/path/to/resin-os.bmap' ) ) | ||
var blockReadStream = new BlockMap.ReadStream( '/path/to/resin-os.img', blockMap ) | ||
const blockMap = BlockMap.parse(fs.readFileSync('/path/to/resin-os.bmap')) | ||
const blockReadStream = new ReadStream(fileDescriptor, blockMap) | ||
@@ -147,13 +145,13 @@ // The chunk emitted will have two properties set; | ||
// Which can then be used to write only those blocks to the target: | ||
blockReadStream.on( 'readable', function() { | ||
var chunk = null | ||
while( chunk = this.read() ) { | ||
fs.writeSync( fd, chunk.buffer, 0, chunk.buffer.length, chunk.position ) | ||
blockReadStream.on('readable', function() { | ||
len chunk = null | ||
while(chunk = this.read()) { | ||
fs.writeSync(fd, chunk.buffer, 0, chunk.buffer.length, chunk.position) | ||
} | ||
}) | ||
blockReadStream.once( 'end', function() { | ||
console.log( 'Read', blockReadStream.blocksRead, 'mapped blocks' ) | ||
console.log( 'Read', blockReadStream.bytesRead, 'mapped bytes' ) | ||
console.log( 'Read', blockReadStream.rangesRead, 'mapped ranges' ) | ||
blockReadStream.once('end', function() { | ||
console.log('Read', blockReadStream.blocksRead, 'mapped blocks') | ||
console.log('Read', blockReadStream.bytesRead, 'mapped bytes') | ||
console.log('Read', blockReadStream.rangesRead, 'mapped ranges') | ||
}) | ||
@@ -167,5 +165,5 @@ ``` | ||
```js | ||
var blockMap = BlockMap.parse( fs.readFileSync( '/path/to/resin-os.bmap' ) ) | ||
var readStream = fs.createReadStream( '/path/to/resin-os.img' ) | ||
var filterStream = new BlockMap.FilterStream( blockMap ) | ||
const blockMap = BlockMap.parse(fs.readFileSync('/path/to/resin-os.bmap')) | ||
const readStream = fs.createReadStream('/path/to/resin-os.img') | ||
const filterStream = new FilterStream(blockMap) | ||
@@ -176,6 +174,6 @@ // The chunk emitted will have two properties set; | ||
// Which can then be used to write only those blocks to the target: | ||
filterStream.on( 'readable', function() { | ||
var buffer = null | ||
while( chunk = this.read() ) { | ||
fs.writeSync( fd, chunk.buffer, 0, chunk.buffer.length, chunk.position ) | ||
filterStream.on('readable', function() { | ||
let buffer = null | ||
while(chunk = this.read()) { | ||
fs.writeSync(fd, chunk.buffer, 0, chunk.buffer.length, chunk.position) | ||
} | ||
@@ -185,3 +183,3 @@ }) | ||
// Pipe the readable stream into the block filter: | ||
readStream.pipe( filterStream ) | ||
readStream.pipe(filterStream) | ||
``` | ||
@@ -191,15 +189,17 @@ | ||
Use a `BlockMap.ReadStream` to verify a flashed device image: | ||
Use a `ReadStream` to verify a flashed device image: | ||
```js | ||
function verify( devicePath, blockMap, callback ) { | ||
new BlockMap.ReadStream( devicePath, blockMap ).resume() | ||
.once( 'error', callback ) | ||
.once( 'end', callback ) | ||
const { ReadStream } = require('blockmap'); | ||
function verify(fileDescriptor, blockMap, callback) { | ||
new ReadStream(fileDescriptor, blockMap).resume() | ||
.once('error', callback) | ||
.once('end', callback) | ||
} | ||
var blockMap = BlockMap.parse( fs.readFileSync( '/path/to/resin-os.bmap' ) ) | ||
const blockMap = BlockMap.parse(fs.readFileSync('/path/to/resin-os.bmap')) | ||
verify( '/dev/rdisk4', blockMap, function( error ) { | ||
if( error != null ) { | ||
verify(fileDescriptor, blockMap, function(error) { | ||
if(error != null) { | ||
// The image didn't verify... | ||
@@ -219,5 +219,4 @@ } | ||
try { | ||
blockMap = BlockMap.parse( value ) // OR | ||
blockMap.parse( value ) | ||
} catch( error ) { | ||
blockMap = BlockMap.parse(value) | ||
} catch(error) { | ||
// ... | ||
@@ -234,8 +233,8 @@ } | ||
```js | ||
var blockReadStream = new BlockMap.ReadStream( '/path/to/resin-os.img', blockMap ) | ||
const blockReadStream = new ReadStream(fileDescriptor, blockMap) | ||
blockReadStream.on( 'error', function( error ) { | ||
if( error.checksum ) { | ||
console.log( `Checksum mismatch for range [${error.range.start},${error.range.end}]:` ) | ||
console.log( `${error.checksum} != ${error.range.checksum}` ) | ||
blockReadStream.on('error', function(error) { | ||
if(error.checksum) { | ||
console.log(`Checksum mismatch for range [${error.range.start},${error.range.end}]:`) | ||
console.log(`${error.checksum} != ${error.range.checksum}`) | ||
} | ||
@@ -242,0 +241,0 @@ // ... |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
0
118018
11
2147
236