partitioninfo
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -80,6 +80,6 @@ var BOOT_RECORD_SIZE, MasterBootRecord, Promise, fs; | ||
return exports.read(image, position).then(function(buffer) { | ||
var result; | ||
var error, result; | ||
try { | ||
result = exports.parse(buffer); | ||
} catch (_error) { | ||
} catch (error) { | ||
return; | ||
@@ -86,0 +86,0 @@ } |
@@ -1,5 +0,3 @@ | ||
var Promise, SECTOR_SIZE, bootRecord, fs, _; | ||
var Promise, SECTOR_SIZE, bootRecord, fs; | ||
_ = require('lodash'); | ||
Promise = require('bluebird'); | ||
@@ -38,36 +36,2 @@ | ||
/** | ||
* @summary Get a partition offset | ||
* @protected | ||
* @function | ||
* | ||
* @param {Object} partition - partition | ||
* @returns {Number} partition offset | ||
* | ||
* @example | ||
* offset = partition.getPartitionOffset(myPartition) | ||
*/ | ||
exports.getPartitionOffset = function(partition) { | ||
return partition.firstLBA * SECTOR_SIZE; | ||
}; | ||
/** | ||
* @summary Get the partition size in bytes | ||
* @protected | ||
* @function | ||
* | ||
* @param {Object} partition - partition | ||
* @returns {Number} partition size | ||
* | ||
* @example | ||
* size = partition.getPartitionSize(myPartition) | ||
*/ | ||
exports.getPartitionSize = function(partition) { | ||
return partition.sectors * SECTOR_SIZE; | ||
}; | ||
/** | ||
* @summary Get a partition object from a definition | ||
@@ -96,3 +60,3 @@ * @protected | ||
} | ||
primaryPartitionOffset = exports.getPartitionOffset(primaryPartition); | ||
primaryPartitionOffset = primaryPartition.byteOffset(); | ||
return bootRecord.getExtended(image, primaryPartitionOffset).then(function(ebr) { | ||
@@ -99,0 +63,0 @@ var logicalPartition; |
@@ -1,8 +0,14 @@ | ||
var Promise, partition; | ||
var MBR, Promise, _, bootRecord, getPartitions, partition; | ||
Promise = require('bluebird'); | ||
_ = require('lodash'); | ||
MBR = require('mbr'); | ||
partition = require('./partition'); | ||
bootRecord = require('./boot-record'); | ||
/** | ||
@@ -37,6 +43,50 @@ * @module partitioninfo | ||
return Promise.props({ | ||
offset: partition.getPartitionOffset(parsedPartition), | ||
size: partition.getPartitionSize(parsedPartition) | ||
offset: parsedPartition.byteOffset(), | ||
size: parsedPartition.byteSize() | ||
}); | ||
}); | ||
}; | ||
/** | ||
* @summary Read all partition tables from a disk image recursively. | ||
* @public | ||
* @function | ||
* | ||
* @param {String} image - image path | ||
* @param {Number} [offset=0] - where the first partition table will be read from, in bytes | ||
* | ||
* @returns {Promise<Array<Object>>} partitions information | ||
* | ||
* @example | ||
* partitioninfo.getPartitions('foo/bar.img') | ||
* .then (information) -> | ||
* for partition in information | ||
* console.log(partition.offset) | ||
* console.log(partition.size) | ||
*/ | ||
exports.getPartitions = getPartitions = function(image, offset) { | ||
if (offset == null) { | ||
offset = 0; | ||
} | ||
return Promise["try"](function() { | ||
if (offset === 0) { | ||
return bootRecord.getMaster(image); | ||
} else { | ||
return bootRecord.getExtended(image, offset); | ||
} | ||
}).get('partitions').filter(_.property('type')).map(function(partition) { | ||
partition = { | ||
offset: offset + partition.byteOffset(), | ||
size: partition.byteSize(), | ||
type: partition.type | ||
}; | ||
if (!MBR.Partition.isExtended(partition.type)) { | ||
return [partition]; | ||
} | ||
return getPartitions(image, partition.offset).then(function(ps) { | ||
return [partition].concat(ps); | ||
}); | ||
}).then(_.flatten); | ||
}; |
@@ -8,2 +8,6 @@ # Change Log | ||
### Added | ||
- Implement `.getPartitions()`. | ||
### Changed | ||
@@ -19,3 +23,4 @@ | ||
[1.0.2]: https://github.com/jviotti/partitioninfo/compare/v1.0.1...v1.0.2 | ||
[1.0.1]: https://github.com/jviotti/partitioninfo/compare/v1.0.0...v1.0.1 | ||
[1.1.0]: https://github.com/resin-io-modules/partitioninfo/compare/v1.0.2...v1.1.0 | ||
[1.0.2]: https://github.com/resin-io-modules/partitioninfo/compare/v1.0.1...v1.0.2 | ||
[1.0.1]: https://github.com/resin-io-modules/partitioninfo/compare/v1.0.0...v1.0.1 |
{ | ||
"name": "partitioninfo", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Get information about a partition from an image file", | ||
"main": "build/partitioninfo.js", | ||
"homepage": "https://github.com/jviotti/partitioninfo", | ||
"homepage": "https://github.com/resin-io-modules/partitioninfo", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/jviotti/partitioninfo.git" | ||
"url": "git://github.com/resin-io-modules/partitioninfo.git" | ||
}, | ||
@@ -25,19 +25,19 @@ "keywords": [ | ||
}, | ||
"author": "Juan Cruz Viotti <juanchiviotti@gmail.com>", | ||
"author": "Juan Cruz Viotti <juan@resin.io>", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"coffee-script": "~1.8.0", | ||
"gulp": "~3.8.10", | ||
"gulp-coffee": "~2.2.0", | ||
"gulp-coffeelint": "~0.4.0", | ||
"gulp-mocha": "~2.0.0", | ||
"gulp-util": "~3.0.1", | ||
"jsdoc-to-markdown": "^1.1.1", | ||
"mocha": "~2.0.1", | ||
"coffee-script": "^1.10.0", | ||
"gulp": "^3.9.1", | ||
"gulp-coffee": "^2.3.1", | ||
"gulp-coffeelint": "^0.6.0", | ||
"gulp-mocha": "^2.2.0", | ||
"gulp-util": "^3.0.7", | ||
"jsdoc-to-markdown": "^1.3.3", | ||
"lodash": "^4.6.1", | ||
"mocha": "^2.4.5", | ||
"mochainon": "^1.0.0", | ||
"mock-fs": "^3.0.0" | ||
"mock-fs": "^3.8.0" | ||
}, | ||
"dependencies": { | ||
"bluebird": "^2.9.32", | ||
"lodash": "^3.10.0", | ||
"bluebird": "^3.3.4", | ||
"mbr": "^0.4.4", | ||
@@ -44,0 +44,0 @@ "tmp": "0.0.28" |
partitioninfo | ||
------------- | ||
============= | ||
> Get information about a partition from an image file. | ||
[![npm version](https://badge.fury.io/js/partitioninfo.svg)](http://badge.fury.io/js/partitioninfo) | ||
[![dependencies](https://david-dm.org/jviotti/partitioninfo.png)](https://david-dm.org/jviotti/partitioninfo.png) | ||
[![Build Status](https://travis-ci.org/jviotti/partitioninfo.svg?branch=master)](https://travis-ci.org/jviotti/partitioninfo) | ||
[![Build status](https://ci.appveyor.com/api/projects/status/udif66t2rsxb43xt?svg=true)](https://ci.appveyor.com/project/jviotti/partitioninfo) | ||
[![dependencies](https://david-dm.org/resin-io-modules/partitioninfo.svg)](https://david-dm.org/resin-io-modules/partitioninfo.svg) | ||
[![Build Status](https://travis-ci.org/resin-io-modules/partitioninfo.svg?branch=master)](https://travis-ci.org/resin-io-modules/partitioninfo) | ||
[![Build status](https://ci.appveyor.com/api/projects/status/udif66t2rsxb43xt/branch/master?svg=true)](https://ci.appveyor.com/project/resin-io/partitioninfo/branch/master) | ||
[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/resin-io/chat) | ||
Get information about a partition from an image file. | ||
Installation | ||
@@ -23,2 +24,7 @@ ------------ | ||
* [partitioninfo](#module_partitioninfo) | ||
* [.get(image, definition)](#module_partitioninfo.get) ⇒ <code>Promise.<Object></code> | ||
* [.getPartitions(image, [offset])](#module_partitioninfo.getPartitions) ⇒ <code>Promise.<Array.<Object>></code> | ||
<a name="module_partitioninfo.get"></a> | ||
@@ -47,7 +53,27 @@ ### partitioninfo.get(image, definition) ⇒ <code>Promise.<Object></code> | ||
``` | ||
<a name="module_partitioninfo.getPartitions"></a> | ||
### partitioninfo.getPartitions(image, [offset]) ⇒ <code>Promise.<Array.<Object>></code> | ||
**Kind**: static method of <code>[partitioninfo](#module_partitioninfo)</code> | ||
**Summary**: Read all partition tables from a disk image recursively. | ||
**Returns**: <code>Promise.<Array.<Object>></code> - partitions information | ||
**Access:** public | ||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| image | <code>String</code> | | image path | | ||
| [offset] | <code>Number</code> | <code>0</code> | where the first partition table will be read from, in bytes | | ||
**Example** | ||
```js | ||
partitioninfo.getPartitions('foo/bar.img') | ||
.then (information) -> | ||
for partition in information | ||
console.log(partition.offset) | ||
console.log(partition.size) | ||
``` | ||
Support | ||
------- | ||
If you're having any problem, please [raise an issue](https://github.com/jviotti/partitioninfo/issues/new) on GitHub and the Resin.io team will be happy to help. | ||
If you're having any problem, please [raise an issue](https://github.com/resin-io-modules/partitioninfo/issues/new) on GitHub and the Resin.io team will be happy to help. | ||
@@ -66,4 +92,4 @@ Tests | ||
- Issue Tracker: [github.com/jviotti/partitioninfo/issues](https://github.com/jviotti/partitioninfo/issues) | ||
- Source Code: [github.com/jviotti/partitioninfo](https://github.com/jviotti/partitioninfo) | ||
- Issue Tracker: [github.com/resin-io-modules/partitioninfo/issues](https://github.com/resin-io-modules/partitioninfo/issues) | ||
- Source Code: [github.com/resin-io-modules/partitioninfo](https://github.com/resin-io-modules/partitioninfo) | ||
@@ -70,0 +96,0 @@ Before submitting a PR, please make sure that you include tests, and that [coffeelint](http://www.coffeelint.org/) runs without any warning: |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
36807
3
355
103
11
+ Addedbluebird@3.7.2(transitive)
- Removedlodash@^3.10.0
- Removedbluebird@2.11.0(transitive)
- Removedlodash@3.10.1(transitive)
Updatedbluebird@^3.3.4