Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

blockdevice

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

blockdevice - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

example/mbr.js

16

lib/blockdevice.js

@@ -19,3 +19,3 @@ var os = require( 'os' )

this.path = options.path
this.mode = options.mode || 'r+'
this.mode = options.mode || 'rs+'

@@ -26,9 +26,19 @@ this.blockSize = options.blockSize || -1

// Heads per Track (for CHS addressing)
this.headsPerTrack = -1
this.headsPerTrack = options.headsPerTrack || -1
// Sectors per Track (for CHS addressing)
this.sectorsPerTrack = -1
this.sectorsPerTrack = options.sectorsPerTrack || -1
Object.defineProperty( this, 'fs', {
enumerable: false
})
}
/**
* Partition Constructor
* @type {Function}
*/
BlockDevice.Partition = require( './partition' )
/**
* Returns physical device path from id

@@ -35,0 +45,0 @@ * @param {Number} id

2

package.json
{
"name": "blockdevice",
"version": "0.2.0",
"version": "0.2.1",
"description": "Block Device",

@@ -5,0 +5,0 @@ "main": "lib/blockdevice",

@@ -12,1 +12,55 @@ # BlockDevice

```
## Usage
```js
var BlockDevice = require( 'blockdevice' )
```
```js
var device = new BlockDevice({
// A custom 'fs' instance, defaults to require( 'fs' ) (optional)
fs: null,
// A file descriptor, if you have (optional)
fd: null,
// Path to the device
path: null,
// Mode defaults to 'rs+' to bypass local cache (optional)
mode: 'rs+',
// Device block size in bytes (optional)
blockSize: -1,
// Device size in bytes (optional)
size: -1,
// Heads per Track (for CHS addressing)
headsPerTrack: -1,
// Sectors per Track (for CHS addressing)
sectorsPerTrack: -1,
})
```
## API
- BlockDevice( options )
- BlockDevice.getPath( id )
- device.open( callback( err, fd ) )
- device.close( callback( err ) )
- device.detectBlockSize( size, step, limit, callback( err, blockSize ) )
- device.detectSize( step, callback( err, size ) )
- device.partition( options )
- device.getLBA( cylinder, head, sector )
- device.read( offset, length, buffer, callback( err, buffer, bytesRead ) )
- device.readLBA( fromLBA, toLBA, buffer, callback( err, buffer, bytesRead ) )
- device.write( offset, buffer, callback( err, bytesWritten ) )
- device.writeLBA( fromLBA, buffer, callback( err, bytesWritten ) )
- BlockDevice.Partition( device, options )
- get partition.blockSize
- get partition.sectors
- get partition.size
- partition.__OOB( lba )
- partition.readBlock( from, to, buffer, callback )
- partition.writeBlock( from, data, callback )

@@ -15,3 +15,3 @@ var util = require( 'util' )

path: BlockDevice.getPath( 2 ),
mode: 'r',
mode: 'rs',
})

@@ -22,2 +22,14 @@

function deviceList() {
BlockDevice.getDeviceList( function( error, list ) {
log( '' )
log( 'Device List' )
error && inspect( error )
log( '' )
inspect( list )
})
}
function open() {

@@ -96,2 +108,2 @@ device.open( function( error ) {

open()
deviceList()

@@ -14,5 +14,6 @@ var util = require( 'util' )

var device = new BlockDevice({
// path: '\\\\.\\Device\\000000a5',
// path: '\\\\?\\Volume{d4c2f71f-76fd-11e4-95f2-98fe943deec6}\\',
path: BlockDevice.getPath( 2 ),
mode: 'r+',
// path: '\\\\.\\F:',
mode: 'rs+',
})

@@ -90,5 +91,7 @@

var blockSize = 512
var lba = ( sectors - 1 )
var lba = ( 40 )
var helloWorld = new Buffer( 'Hello World' )
var length = helloWorld.length
var fill = new Buffer( blockSize - helloWorld.length )
fill.fill( 0 )
var helloWorld = Buffer.concat([ helloWorld, fill ])

@@ -98,3 +101,3 @@ device.writeLBA( lba, helloWorld, function( error, bytesWritten ) {

log( '' )
log( 'Wrote', bytesWritten, 'bytes', '(should be', length, 'bytes)' )
log( 'Wrote', bytesWritten, 'bytes', '(should be', blockSize, 'bytes)' )
error && inspect( error )

@@ -106,2 +109,3 @@ log( '' )

log( 'Read', bytesRead, 'bytes', '(should be', blockSize, 'bytes)' )
log( 'Buffer:', buffer.toString( 'ascii' ).replace( /^\0+|\0+$/, '' ) )
log( buffer )

@@ -108,0 +112,0 @@ error && inspect( error )

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc