Socket
Socket
Sign inDemoInstall

bare-fs

Package Overview
Dependencies
Maintainers
2
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bare-fs - npm Package Compare versions

Comparing version 1.11.0 to 1.12.0

243

index.js

@@ -15,2 +15,7 @@ const { sep, resolve, isAbsolute, toNamespacedPath } = require('path')

F_OK: binding.F_OK || 0,
R_OK: binding.R_OK || 0,
W_OK: binding.W_OK || 0,
X_OK: binding.X_OK || 0,
S_IFMT: binding.S_IFMT,

@@ -208,2 +213,29 @@ S_IFREG: binding.S_IFREG,

function access (path, mode, cb) {
if (typeof path !== 'string') {
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof path) + ' (' + path + ')')
}
if (typeof cb !== 'function') {
if (typeof mode === 'function') {
cb = mode
mode = constants.F_OK
} else {
throw typeError('ERR_INVALID_ARG_TYPE', 'Callback must be a function. Received type ' + (typeof cb) + ' (' + cb + ')')
}
}
const req = getReq()
req.callback = cb
binding.access(req.handle, path, mode)
}
function accessSync (path, mode = constants.F_OK) {
if (typeof path !== 'string') {
throw typeError('ERR_INVALID_ARG_TYPE', 'Path must be a string. Received type ' + (typeof path) + ' (' + path + ')')
}
binding.accessSync(path, mode)
}
function read (fd, buffer, offset, len, pos, cb) {

@@ -1305,105 +1337,2 @@ if (typeof fd !== 'number') {

class FileWriteStream extends Writable {
constructor (path, opts = {}) {
super({ map })
this.path = path
this.fd = 0
this.flags = opts.flags || 'w'
this.mode = opts.mode || 0o666
}
_open (cb) {
open(this.path, this.flags, this.mode, (err, fd) => {
if (err) return cb(err)
this.fd = fd
cb(null)
})
}
_writev (datas, cb) {
writev(this.fd, datas, cb)
}
_destroy (cb) {
if (!this.fd) return cb(null)
close(this.fd, () => cb(null))
}
}
class FileReadStream extends Readable {
constructor (path, opts = {}) {
super()
this.path = path
this.fd = 0
this._offset = opts.start || 0
this._missing = 0
if (opts.length) this._missing = opts.length
else if (typeof opts.end === 'number') this._missing = opts.end - this._offset + 1
else this._missing = -1
}
_open (cb) {
open(this.path, constants.O_RDONLY, (err, fd) => {
if (err) return cb(err)
const onerror = (err) => close(fd, () => cb(err))
fstat(fd, (err, st) => {
if (err) return onerror(err)
if (!st.isFile()) return onerror(new Error(this.path + ' is not a file'))
this.fd = fd
if (this._missing === -1) this._missing = st.size
if (st.size < this._offset) {
this._offset = st.size
this._missing = 0
return cb(null)
}
if (st.size < this._offset + this._missing) {
this._missing = st.size - this._offset
return cb(null)
}
cb(null)
})
})
}
_read (cb) {
if (!this._missing) {
this.push(null)
return cb(null)
}
const data = Buffer.allocUnsafe(Math.min(this._missing, 65536))
read(this.fd, data, 0, data.byteLength, this._offset, (err, read) => {
if (err) return cb(err)
if (!read) {
this.push(null)
return cb(null)
}
if (this._missing < read) read = this._missing
this.push(data.subarray(0, read))
this._missing -= read
this._offset += read
if (!this._missing) this.push(null)
cb(null)
})
}
_destroy (cb) {
if (!this.fd) return cb(null)
close(this.fd, () => cb(null))
}
}
class Dir {

@@ -1564,2 +1493,105 @@ constructor (path, handle, opts = {}) {

class FileWriteStream extends Writable {
constructor (path, opts = {}) {
super({ map })
this.path = path
this.fd = 0
this.flags = opts.flags || 'w'
this.mode = opts.mode || 0o666
}
_open (cb) {
open(this.path, this.flags, this.mode, (err, fd) => {
if (err) return cb(err)
this.fd = fd
cb(null)
})
}
_writev (datas, cb) {
writev(this.fd, datas, cb)
}
_destroy (cb) {
if (!this.fd) return cb(null)
close(this.fd, () => cb(null))
}
}
class FileReadStream extends Readable {
constructor (path, opts = {}) {
super()
this.path = path
this.fd = 0
this._offset = opts.start || 0
this._missing = 0
if (opts.length) this._missing = opts.length
else if (typeof opts.end === 'number') this._missing = opts.end - this._offset + 1
else this._missing = -1
}
_open (cb) {
open(this.path, constants.O_RDONLY, (err, fd) => {
if (err) return cb(err)
const onerror = (err) => close(fd, () => cb(err))
fstat(fd, (err, st) => {
if (err) return onerror(err)
if (!st.isFile()) return onerror(new Error(this.path + ' is not a file'))
this.fd = fd
if (this._missing === -1) this._missing = st.size
if (st.size < this._offset) {
this._offset = st.size
this._missing = 0
return cb(null)
}
if (st.size < this._offset + this._missing) {
this._missing = st.size - this._offset
return cb(null)
}
cb(null)
})
})
}
_read (cb) {
if (!this._missing) {
this.push(null)
return cb(null)
}
const data = Buffer.allocUnsafe(Math.min(this._missing, 65536))
read(this.fd, data, 0, data.byteLength, this._offset, (err, read) => {
if (err) return cb(err)
if (!read) {
this.push(null)
return cb(null)
}
if (this._missing < read) read = this._missing
this.push(data.subarray(0, read))
this._missing -= read
this._offset += read
if (!this._missing) this.push(null)
cb(null)
})
}
_destroy (cb) {
if (!this.fd) return cb(null)
close(this.fd, () => cb(null))
}
}
exports.promises = {}

@@ -1575,2 +1607,3 @@

exports.access = access
exports.chmod = chmod

@@ -1601,2 +1634,3 @@ exports.close = close

exports.accessSync = accessSync
exports.chmodSync = chmodSync

@@ -1624,2 +1658,3 @@ exports.closeSync = closeSync

exports.promises.access = promisify(access)
exports.promises.chmod = promisify(chmod)

@@ -1642,2 +1677,4 @@ exports.promises.lstat = promisify(lstat)

exports.Stats = Stats
exports.Dir = Dir
exports.Dirent = Dirent

@@ -1644,0 +1681,0 @@ exports.ReadStream = FileReadStream

{
"name": "bare-fs",
"version": "1.11.0",
"version": "1.12.0",
"description": "Native file system for Javascript",

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

@@ -16,2 +16,3 @@ # bare-fs

fs.access
fs.chmod

@@ -42,2 +43,3 @@ fs.close

fs.promises.access
fs.promises.chmod

@@ -61,2 +63,3 @@ fs.promises.lstat

fs.accessSync
fs.chmodSync

@@ -63,0 +66,0 @@ fs.closeSync

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