Comparing version 4.0.0-typescript-0ea0a4837bfc224c2663be2c9d3f628144385674 to 4.0.0-typescript-5ea81fecfa605802b2bf2bd68c59a7ee8dafbe14
@@ -7,4 +7,7 @@ # Change Log | ||
## 4.0.0 - 2019-03-26 | ||
## 4.0.0 - 2019-04-04 | ||
* Remove travis and appveyor configs [Alexis Svinartchouk] | ||
* Don't test on node 4 [Alexis Svinartchouk] | ||
* Replace jsdoc with typedoc, rename resin -> balena [Alexis Svinartchouk] | ||
* Change licence MIT -> Apache [Alexis Svinartchouk] | ||
@@ -11,0 +14,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-5ea81fecfa605802b2bf2bd68c59a7ee8dafbe14", | ||
"description": "Tizen's block map format", | ||
@@ -26,15 +26,16 @@ "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" | ||
}, | ||
"homepage": "https://github.com/resin-io-modules/blockmap", | ||
"homepage": "https://github.com/balena-io-modules/blockmap", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/resin-io-modules/blockmap.git" | ||
"url": "git+https://github.com/balena-io-modules/blockmap.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/resin-io-modules/blockmap/issues" | ||
"url": "https://github.com/balena-io-modules/blockmap/issues" | ||
}, | ||
@@ -47,5 +48,5 @@ "scripts": { | ||
"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" | ||
} | ||
} |
@@ -5,4 +5,2 @@ # 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/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) | ||
@@ -22,6 +20,6 @@ This module implements [Tizen's block map format](https://source.tizen.org/documentation/reference/bmaptool/introduction), | ||
For detailed API documentation, see [`/doc`](https://github.com/resin-io-modules/blockmap/tree/master/doc). | ||
For detailed API documentation, see [`/doc`](https://github.com/balena-io-modules/blockmap/tree/master/doc). | ||
```js | ||
var BlockMap = require( 'blockmap' ) | ||
const { BlockMap } = require('blockmap') | ||
``` | ||
@@ -32,3 +30,3 @@ | ||
``` | ||
var blockMap = BlockMap.parse( xml ) | ||
const blockMap = BlockMap.parse(xml) | ||
``` | ||
@@ -68,4 +66,4 @@ | ||
```js | ||
var blockMap = BlockMap.parse( value ) | ||
var xml = blockMap.toString() | ||
const blockMap = BlockMap.parse(value) | ||
const xml = blockMap.toString() | ||
``` | ||
@@ -104,21 +102,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) | ||
``` | ||
@@ -132,3 +128,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. | ||
@@ -140,4 +136,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/balena-os.bmap')) | ||
const blockReadStream = new ReadStream(fileDescriptor, blockMap) | ||
@@ -148,13 +144,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') | ||
}) | ||
@@ -168,5 +164,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/balena-os.bmap')) | ||
const readStream = fs.createReadStream('/path/to/balena-os.img') | ||
const filterStream = new FilterStream(blockMap) | ||
@@ -177,6 +173,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) | ||
} | ||
@@ -186,3 +182,3 @@ }) | ||
// Pipe the readable stream into the block filter: | ||
readStream.pipe( filterStream ) | ||
readStream.pipe(filterStream) | ||
``` | ||
@@ -192,15 +188,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/balena-os.bmap')) | ||
verify( '/dev/rdisk4', blockMap, function( error ) { | ||
if( error != null ) { | ||
verify(fileDescriptor, blockMap, function(error) { | ||
if(error != null) { | ||
// The image didn't verify... | ||
@@ -220,5 +218,4 @@ } | ||
try { | ||
blockMap = BlockMap.parse( value ) // OR | ||
blockMap.parse( value ) | ||
} catch( error ) { | ||
blockMap = BlockMap.parse(value) | ||
} catch(error) { | ||
// ... | ||
@@ -235,8 +232,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}`) | ||
} | ||
@@ -243,0 +240,0 @@ // ... |
Sorry, the diff of this file is not supported yet
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
117404
11
41
2147
234