partitioninfo
Advanced tools
Comparing version 1.3.0 to 2.0.0
@@ -1,2 +0,2 @@ | ||
var BOOT_RECORD_SIZE, MBR, Promise, _, callWithDisk, filedisk, get, getLogicalPartitions, getPartitionFromList, getPartitions, getPartitionsFromMBRBuf, partitionDict, readMbr, | ||
var BOOT_RECORD_SIZE, MBR, Promise, _, callWithDisk, filedisk, get, getLogicalPartitions, getPartitions, getPartitionsFromMBRBuf, partitionDict, partitionNotFoundError, readMbr, | ||
slice = [].slice; | ||
@@ -89,22 +89,30 @@ | ||
getPartitionFromList = function(partitions, number) { | ||
var partition; | ||
partition = partitions[number - 1]; | ||
if (!partition) { | ||
throw new Error("Partition not found: " + number + "."); | ||
} | ||
return partition; | ||
partitionNotFoundError = function(number) { | ||
throw new Error("Partition not found: " + number + "."); | ||
}; | ||
get = function(disk, definition) { | ||
get = function(disk, number) { | ||
if (number < 1) { | ||
throw new Error('The partition number must be at least 1.'); | ||
} | ||
return getPartitions(disk, 0, false).then(function(partitions) { | ||
var primary; | ||
primary = getPartitionFromList(partitions, definition.primary); | ||
if (!definition.logical) { | ||
return primary; | ||
} else if (!MBR.Partition.isExtended(primary.type)) { | ||
throw new Error("Not an extended partition: " + definition.primary + "."); | ||
var last, logicalPartitionPosition, position; | ||
position = number - 1; | ||
if (partitions.length === 0) { | ||
return partitionNotFoundError(number); | ||
} else if (position < partitions.length) { | ||
return partitions[position]; | ||
} else { | ||
return getLogicalPartitions(disk, primary.offset, primary.offset, definition.logical - 1).then(function(logicalPartitions) { | ||
return getPartitionFromList(logicalPartitions, definition.logical); | ||
last = partitions[partitions.length - 1]; | ||
if (!MBR.Partition.isExtended(last.type)) { | ||
partitionNotFoundError(number); | ||
} | ||
logicalPartitionPosition = position - partitions.length; | ||
return getLogicalPartitions(disk, last.offset, last.offset, logicalPartitionPosition).then(function(logicalPartitions) { | ||
var logical; | ||
logical = logicalPartitions[logicalPartitionPosition]; | ||
if (!logical) { | ||
partitionNotFoundError(number); | ||
} | ||
return logical; | ||
}); | ||
@@ -136,5 +144,3 @@ } | ||
* @param {String|filedisk.Disk} image - image path or filedisk.Disk instance | ||
* @param {Object} definition - partition definition | ||
* @param {Number} definition.primary - primary partition | ||
* @param {Number} [definition.logical] - logical partition | ||
* @param {Object} number - partition number | ||
* | ||
@@ -153,4 +159,4 @@ * @returns {Promise<Object>} partition information | ||
exports.get = function(disk, definition) { | ||
return callWithDisk(get, disk, definition); | ||
exports.get = function(disk, number) { | ||
return callWithDisk(get, disk, number); | ||
}; | ||
@@ -157,0 +163,0 @@ |
{ | ||
"name": "partitioninfo", | ||
"version": "1.3.0", | ||
"version": "2.0.0", | ||
"description": "Get information about a partition from an image file", | ||
@@ -26,2 +26,6 @@ "main": "build/partitioninfo.js", | ||
"author": "Juan Cruz Viotti <juan@resin.io>", | ||
"contributors": [ | ||
"Alexis Svinartchouk <alexis@resin.io>", | ||
"Juan Cruz Viotti <juan@resin.io>" | ||
], | ||
"license": "MIT", | ||
@@ -28,0 +32,0 @@ "devDependencies": { |
@@ -26,3 +26,3 @@ partitioninfo | ||
* [partitioninfo](#module_partitioninfo) | ||
* [.get(image, definition)](#module_partitioninfo.get) ⇒ <code>Promise.<Object></code> | ||
* [.get(image, number)](#module_partitioninfo.get) ⇒ <code>Promise.<Object></code> | ||
* [.getPartitions(image, [offset])](#module_partitioninfo.getPartitions) ⇒ <code>Promise.<Array.<Object>></code> | ||
@@ -32,3 +32,3 @@ | ||
### partitioninfo.get(image, definition) ⇒ <code>Promise.<Object></code> | ||
### partitioninfo.get(image, number) ⇒ <code>Promise.<Object></code> | ||
**Kind**: static method of <code>[partitioninfo](#module_partitioninfo)</code> | ||
@@ -42,5 +42,3 @@ **Summary**: Get information from a partition | ||
| image | <code>String</code> | <code>filedisk.Disk</code> | image path or filedisk.Disk instance | | ||
| definition | <code>Object</code> | partition definition | | ||
| definition.primary | <code>Number</code> | primary partition | | ||
| [definition.logical] | <code>Number</code> | logical partition | | ||
| number | <code>Object</code> | partition number | | ||
@@ -47,0 +45,0 @@ **Example** |
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
292
5275098
105