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

aligned-block-file

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aligned-block-file - npm Package Compare versions

Comparing version 0.1.4 to 1.0.0

10

blocks.js

@@ -43,3 +43,4 @@ var fs = require('fs')

var i = ~~(start/block_size)
if(file && end > file.offset.value)
return cb(new Error('past end'), null, 0)
var bufs = []

@@ -51,3 +52,3 @@ ;(function next (i) {

//this is not right.
if(bytes_read === 0) return cb(new Error('past end'), block, bytes_read)
if(bytes_read === 0) return cb(new Error('past end'), null, bytes_read)

@@ -154,2 +155,7 @@ var read_start = start - block_start

})
},
//we arn't specifically clearing the buffers,
//but they should get updated anyway.
truncate: file ? file.truncate : function (len, cb) {
cb()
}

@@ -156,0 +162,0 @@ }

24

file.js

@@ -54,5 +54,4 @@ var fs = require('fs')

fd.once(function (_fd) {
if('object' === typeof _fd) {
if('object' === typeof _fd)
return cb(_fd)
}
offset.once(function (_offset) {

@@ -68,2 +67,19 @@ fs.write(_fd, buf, 0, buf.length, _offset, function (err, written) {

})
},
truncate: function (len, cb) {
if(writing++) throw new Error('already writing, cannot truncate')
fd.once(function (_fd) {
if('object' === typeof _fd)
return cb(_fd)
offset.once(function (_offset) {
if(_offset <= len) return cb()
fs.ftruncate(_fd, len, function (err) {
if(err) cb(err)
else {
offset.set(len)
cb(null, offset.value)
}
})
})
})
}

@@ -73,5 +89,1 @@ }

{
"name": "aligned-block-file",
"description": "",
"version": "0.1.4",
"version": "1.0.0",
"homepage": "https://github.com/flumedb/aligned-block-file",

@@ -6,0 +6,0 @@ "repository": {

@@ -40,2 +40,6 @@ # aligned-block-file

### truncate(length, cb)
shorten the file to `length` removing anything after that point.
## License

@@ -42,0 +46,0 @@

@@ -38,3 +38,8 @@

t.equal(offset, 32)
t.end()
blocks.read(0, 33, function (err, over, bytes) {
t.ok(err)
t.equal(bytes, 0)
t.end()
})
})

@@ -67,3 +72,4 @@

blocks = reduce(blocks)
blocks.read(64, 96, function (err, _c) {
blocks.read(64, 80, function (err, _c) {
console.log(blocks.offset.value)
if(err) throw err

@@ -116,4 +122,3 @@ console.log(_c)

blocks.read(o, o+16, function (err, buf) {
if(err) throw err
t.deepEqual(buf, c.slice(0, 16))
t.ok(err)
})

@@ -148,3 +153,20 @@ })

tape('truncate', function (t) {
blocks = reduce(blocks)
blocks.truncate(64, function (err, len) {
if(err) throw err
t.equal(blocks.offset.value, 64)
t.equal(len, 64)
blocks.read(0, 64, function (err, ab) {
t.deepEqual(ab, Buffer.concat([a, b]))
blocks.read(64, 96, function (err, _c, bytes) {
t.ok(err)
t.equal(bytes, 0)
t.equal(_c, null)
t.end()
})
})
})
})

@@ -165,3 +187,1 @@ }

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