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

sonic-boom

Package Overview
Dependencies
Maintainers
4
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sonic-boom - npm Package Compare versions

Comparing version 2.0.2 to 2.1.0

19

index.js

@@ -6,2 +6,3 @@ 'use strict'

const inherits = require('util').inherits
const path = require('path')

@@ -68,5 +69,7 @@ const BUSY_WRITE_TIMEOUT = 100

const mode = sonic.append ? 'a' : 'w'
if (sonic.sync) {
try {
const fd = fs.openSync(file, 'a')
if (sonic.mkdir) fs.mkdirSync(path.dirname(file), { recursive: true })
const fd = fs.openSync(file, mode)
fileOpened(null, fd)

@@ -77,4 +80,9 @@ } catch (err) {

}
} else if (sonic.mkdir) {
fs.mkdir(path.dirname(file), { recursive: true }, (err) => {
if (err) return fileOpened(err)
fs.open(file, mode, fileOpened)
})
} else {
fs.open(file, 'a', fileOpened)
fs.open(file, mode, fileOpened)
}

@@ -88,3 +96,3 @@ }

let { fd, dest, minLength, sync } = opts || {}
let { fd, dest, minLength, sync, append = true, mkdir } = opts || {}

@@ -102,6 +110,7 @@ fd = fd || dest

this.destroyed = false
this.minLength = minLength || 0
this.sync = sync || false
this.append = append || false
this.mkdir = mkdir || false
this.minLength = minLength || 0
if (typeof fd === 'number') {

@@ -108,0 +117,0 @@ this.fd = fd

{
"name": "sonic-boom",
"version": "2.0.2",
"version": "2.1.0",
"description": "Extremely fast utf8 only stream implementation",

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

@@ -60,6 +60,8 @@ # sonic-boom

`fs.openSync`.
* `dest`: a string that is a path to a file to be written to (mode `'a'`).
* `minLength`: the minimum lenght of the internal buffer that is
* `dest`: a string that is a path to a file to be written to (mode controlled by the `append` option).
* `minLength`: the minimum length of the internal buffer that is
required to be full before flushing.
* `sync`: perform writes synchronously (similar to `console.log`).
* `append`: appends writes to dest file instead of truncating it (default `true`).
* `mkdir`: ensure directory for dest file exists when `true` (default `false`).

@@ -66,0 +68,0 @@ For `sync:false` a `SonicBoom` instance will emit the `'ready'` event when a file descriptor is available.

@@ -254,2 +254,55 @@ 'use strict'

test('append', (t) => {
t.plan(4)
const dest = file()
fs.writeFileSync(dest, 'hello world\n')
const stream = new SonicBoom({ dest, append: false, sync })
stream.on('ready', () => {
t.pass('ready emitted')
})
t.ok(stream.write('something else\n'))
stream.flush()
stream.on('drain', () => {
fs.readFile(dest, 'utf8', (err, data) => {
t.error(err)
t.equal(data, 'something else\n')
stream.end()
})
})
})
test('mkdir', (t) => {
t.plan(4)
const dest = path.join(file(), 'out.log')
const stream = new SonicBoom({ dest, mkdir: true, sync })
stream.on('ready', () => {
t.pass('ready emitted')
})
t.ok(stream.write('hello world\n'))
stream.flush()
stream.on('drain', () => {
fs.readFile(dest, 'utf8', (err, data) => {
t.error(err)
t.equal(data, 'hello world\n')
stream.end()
// put file where teardown can access it
const { dir, base } = path.parse(dest)
const tmpDir = dir + '~'
fs.renameSync(dir, tmpDir)
fs.renameSync(path.join(tmpDir, base), dir)
fs.rmdirSync(tmpDir)
})
})
})
test('flush', (t) => {

@@ -256,0 +309,0 @@ t.plan(5)

@@ -14,2 +14,4 @@ // Type definitions for sonic-boom 0.7

sync?: boolean
append?: boolean
mkdir?: boolean
}

@@ -16,0 +18,0 @@

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