New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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 1.0.0 to 1.1.0

bench/append.js

41

blocks.js
var fs = require('fs')
var uint48be = require('uint48be')
var int53 = require('int53')
/*

@@ -42,3 +45,3 @@ Represent a file, as a table of buffers.

//check if start & end are part of the same buffer
var i = ~~(start/block_size)
var i = Math.floor(start/block_size)
if(file && end > file.offset.value)

@@ -80,5 +83,4 @@ return cb(new Error('past end'), null, 0)

return br = {
read: read,
readUInt32BE: function (start, cb) {
function readInteger(width, reader) {
return function (start, cb) {
var i = Math.floor(start/block_size)

@@ -89,6 +91,6 @@ var _i = start%block_size

//read directly and it's 3x faster.
if(_i < block_size - 4)
if(_i < block_size - width)
get(i, function (err, block) {
if(err) return cb(err)
var value = block.readUInt32BE(start%block_size)
var value = reader(block, start%block_size)
cb(null, value)

@@ -99,7 +101,26 @@ })

else
read(start, start+4, function (err, buf, bytes_read) {
read(start, start+width, function (err, buf, bytes_read) {
if(err) return cb(err)
cb(null, buf.readUInt32BE(0))
var value = reader(buf, 0);
cb(isNaN(value) ? new Error('Number is too large') : null, value)
})
},
}
}
return br = {
read: read,
readUInt32BE: readInteger(4, function(b, offset) {
return b.readUInt32BE(offset)
}),
readUInt48BE: readInteger(6, function(b, offset) {
return uint48be.decode(b, offset)
}),
readUInt64BE: readInteger(8, function(b, offset) {
// int53.readUInt64BE will throw if number is too large
try {
return int53.readUInt64BE(b, offset)
} catch(err) {
return NaN;
}
}),
size: file && file.size,

@@ -117,3 +138,3 @@ offset: file && file.offset,

var b_start = 0
var i = ~~(start/block_size)
var i = Math.floor(start/block_size)
if(i*block_size < _offset) //usually true, unless file length is multiple of block_size

@@ -120,0 +141,0 @@ get(i, function (err) { //this will add the last block to the cache.

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

@@ -12,4 +12,6 @@ "repository": {

"hashlru": "^2.1.0",
"int53": "^0.2.4",
"mkdirp": "^0.5.1",
"obv": "0.0.0"
"obv": "0.0.0",
"uint48be": "^1.0.1"
},

@@ -16,0 +18,0 @@ "devDependencies": {

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