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

random-access-file

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

random-access-file - npm Package Compare versions

Comparing version 2.0.1 to 2.1.0

21

example.js

@@ -1,17 +0,24 @@

var raf = require('./')
var alloc = require('buffer-alloc-unsafe')
var raf = require('random-access-file')
var file = raf('hello.txt')
var file = raf('hello.txt', {length: 0})
var max = 500 * 1024 * 1024
var buf = Buffer.alloc(1024)
buf.fill('lo')
var buf = alloc(1024)
buf.fill('lo')
var offset = 0
write()
function write () {
if (file.length >= 5 * 1024 * 1024) return done()
file.write(file.length, buf, write)
file.write(offset, buf, afterWrite)
}
function afterWrite (err) {
if (err) throw err
if (offset >= max) return done()
offset += buf.length
write()
}
function done () {
console.log('wrote hello.txt')
}

@@ -30,2 +30,3 @@ var inherits = require('util').inherits

this._rmdir = !!opts.rmdir
this._lock = opts.lock || noLock
}

@@ -158,2 +159,3 @@

if (err) return onerrorafteropen(err)
if (!self._lock(self.fd)) return req.callback(createLockError(self.filename))
if (!self._truncate || mode === READONLY) return req.callback(null)

@@ -179,1 +181,12 @@ fs.ftruncate(self.fd, self._size, ontruncate)

}
function noLock (fd) {
return true
}
function createLockError (path) {
var err = new Error('ELOCKED: File is locked')
err.code = 'ELOCKED'
err.path = path
return err
}
{
"name": "random-access-file",
"version": "2.0.1",
"version": "2.1.0",
"description": "Continuous reading or writing to a file using random offsets and lengths",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -48,3 +48,4 @@ # random-access-file

readable: true, // should the file be opened as readable?
writable: true // should the file be opened as writable?
writable: true, // should the file be opened as writable?
lock (fd) => bool // optional function that informs if the file could be locked
}

@@ -66,2 +67,12 @@ ```

#### `file.stat(callback)`
Stat the storage. Should return an object with useful information about the underlying storage, including:
```js
{
size: number // how many bytes of data is stored?
}
```
#### `file.close([callback])`

@@ -68,0 +79,0 @@

@@ -129,11 +129,2 @@ var raf = require('./')

tape('bad truncate', function (t) {
var file = raf(gen(), {writable: true, size: -1, truncate: true})
file.open(function (err) {
t.ok(err)
file.destroy(() => t.end())
})
})
tape('mkdir path', function (t) {

@@ -296,3 +287,3 @@ var name = path.join(tmp, ++i + '-folder', 'test.txt')

file.fd = -1
file.fd = 10000
file.open(function (err) {

@@ -307,4 +298,17 @@ t.ok(err, 'should error trying to close old fd')

tape('trigger lock', function (t) {
var p = gen()
var file = raf(p, {writable: true, lock: () => false})
file.open(function (err) {
t.ok(err, 'should error because it is locked')
t.same(err.message, 'ELOCKED: File is locked')
t.same(err.path, p)
t.same(err.code, 'ELOCKED')
t.end()
})
})
function gen () {
return path.join(tmp, ++i + '.txt')
}

Sorry, the diff of this file is not supported yet

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