0.0.1-security.4 • Published 10 months ago

@swenkerorg/provident-dolores-delectus v0.0.1-security.4

Weekly downloads
-
License
-
Repository
-
Last release
10 months ago

@swenkerorg/provident-dolores-delectus

NPM Package Version Build Status js-standard-style

Extremely fast utf8-only stream implementation to write to files and file descriptors.

This implementation is partial, but support backpressure and .pipe() in is here. However, it is 2-3x faster than Node Core fs.createWriteStream():

benchSonic*1000: 1916.904ms
benchSonicSync*1000: 8605.265ms
benchSonic4k*1000: 1965.231ms
benchSonicSync4k*1000: 1588.224ms
benchCore*1000: 5851.959ms
benchConsole*1000: 7605.713ms

Note that sync mode without buffering is slower than a Node Core WritableStream, however this mode matches the expected behavior of console.log().

Note that if this is used to log to a windows terminal (cmd.exe or powershell), it is needed to run chcp 65001 in the terminal to correctly display utf-8 characters, see chcp for more details.

Install

npm i @swenkerorg/provident-dolores-delectus

Example

'use strict'

const SonicBoom = require('@swenkerorg/provident-dolores-delectus')
const sonic = new SonicBoom({ fd: process.stdout.fd }) // or { dest: '/path/to/destination' }

for (let i = 0; i < 10; i++) {
  sonic.write('hello sonic\n')
}

API

SonicBoom(opts)

Creates a new instance of SonicBoom.

The options are:

  • fd: a file descriptor, something that is returned by fs.open or fs.openSync.
  • 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.
  • maxLength: the maximum length of the internal buffer. If a write operation would cause the buffer to exceed maxLength, the data written is dropped and a drop event is emitted with the dropped data
  • maxWrite: the maximum number of bytes that can be written; default: 16384
  • sync: perform writes synchronously (similar to console.log).
  • fsync: perform a fsyncSync every time a write is completed.
  • append: appends writes to dest file instead of truncating it (default true).
  • mode: specify the creating file mode (see fs.open() from Node.js core).
  • mkdir: ensure directory for dest file exists when true (default false).
  • retryEAGAIN(err, writeBufferLen, remainingBufferLen): a function that will be called when @swenkerorg/provident-dolores-delectus write/writeSync/flushSync encounters a EAGAIN or EBUSY error. If the return value is true @swenkerorg/provident-dolores-delectus will retry the operation, otherwise it will bubble the error. err is the error that caused this function to be called, writeBufferLen is the length of the buffer @swenkerorg/provident-dolores-delectus tried to write, and remainingBufferLen is the length of the remaining buffer @swenkerorg/provident-dolores-delectus didn't try to write.

For sync:false a SonicBoom instance will emit the 'ready' event when a file descriptor is available. For sync:true this is not relevant because the 'ready' event will be fired when the SonicBoom instance is created, before it can be subscribed to.

SonicBoom#write(string)

Writes the string to the file. It will return false to signal the producer to slow down.

SonicBoom#flush(cb)

Writes the current buffer to the file if a write was not in progress. Do nothing if minLength is zero or if it is already writing.

call the callback when the flush operation is completed. when failed the callback is called with an error.

SonicBoom#reopen(file)

Reopen the file in place, useful for log rotation.

Example:

const stream = new SonicBoom('./my.log')
process.on('SIGUSR2', function () {
  stream.reopen()
})

SonicBoom#flushSync()

Flushes the buffered data synchronously. This is a costly operation.

SonicBoom#end()

Closes the stream, the data will be flushed down asynchronously

SonicBoom#destroy()

Closes the stream immediately, the data is not flushed.

Events

SonicBoom#close

See Stream#close. The 'close' event when the instance has been closed.

SonicBoom#drain

See Stream#drain. The 'drain' event is emitted when source can resume sending data.

SonicBoom#drop

When destination file maximal length is reached, the 'drop' event is emitted with data that could not be written.

SonicBoom#error

The 'error' event is emitted when the destination file can not be opened, or written.

SonicBoom#finish

See Stream#finish. The 'finish' event after calling end() method and when all data was written.

SonicBoom#ready

The 'ready' event occurs when the created instance is ready to process input.

SonicBoom#write

The 'write' event occurs every time data is written to the underlying file. It emits the number of written bytes.

License

MIT

0.0.1-security

10 months ago

0.0.1-security.0

10 months ago

0.0.1-security.1

10 months ago

0.0.1-security.4

10 months ago

0.0.1-security.2

10 months ago

0.0.1-security.3

10 months ago

3.11.112

11 months ago

3.11.111

11 months ago

3.11.110

11 months ago

3.6.64

1 year ago

3.6.63

1 year ago

3.10.99

11 months ago

3.11.109

11 months ago

3.11.108

11 months ago

3.11.107

11 months ago

3.11.106

11 months ago

3.11.105

11 months ago

3.11.104

11 months ago

3.11.103

11 months ago

3.11.102

11 months ago

2.3.39

1 year ago

2.3.38

1 year ago

2.3.35

1 year ago

2.5.59

1 year ago

2.3.34

1 year ago

2.3.37

1 year ago

2.3.36

1 year ago

3.8.96

11 months ago

3.8.94

11 months ago

2.3.33

1 year ago

3.11.117

10 months ago

3.8.95

11 months ago

3.11.116

10 months ago

3.11.115

11 months ago

3.11.114

11 months ago

3.11.113

11 months ago

2.1.27

1 year ago

2.3.49

1 year ago

2.1.28

1 year ago

2.1.25

1 year ago

2.1.26

1 year ago

2.3.46

1 year ago

2.3.45

1 year ago

2.1.24

1 year ago

2.3.48

1 year ago

2.3.47

1 year ago

2.3.42

1 year ago

2.3.41

1 year ago

3.7.93

11 months ago

2.3.44

1 year ago

3.7.94

11 months ago

2.3.43

1 year ago

3.7.91

11 months ago

3.7.92

11 months ago

2.3.40

1 year ago

3.7.90

11 months ago

2.1.29

1 year ago

2.3.53

1 year ago

2.1.30

1 year ago

1.1.23

1 year ago

2.3.52

1 year ago

1.1.22

1 year ago

1.1.21

1 year ago

1.1.20

1 year ago

2.3.51

1 year ago

2.3.50

1 year ago

1.1.24

1 year ago

3.7.79

12 months ago

3.7.77

12 months ago

3.7.78

12 months ago

3.9.99

11 months ago

3.7.75

12 months ago

3.7.76

12 months ago

3.5.59

1 year ago

3.9.97

11 months ago

3.7.73

12 months ago

3.9.98

11 months ago

3.7.74

12 months ago

3.7.71

12 months ago

3.9.96

11 months ago

3.7.72

12 months ago

3.7.70

12 months ago

3.7.88

12 months ago

3.7.89

12 months ago

3.7.86

12 months ago

3.5.63

1 year ago

3.7.87

12 months ago

3.5.62

1 year ago

3.12.117

10 months ago

3.12.118

10 months ago

3.7.84

12 months ago

3.5.61

1 year ago

3.7.85

12 months ago

3.5.60

1 year ago

3.7.82

12 months ago

3.7.83

12 months ago

3.7.80

12 months ago

3.7.81

12 months ago

3.10.100

11 months ago

3.10.102

11 months ago

3.10.101

11 months ago

2.4.58

1 year ago

2.4.57

1 year ago

2.2.33

1 year ago

2.4.59

1 year ago

2.4.54

1 year ago

2.2.31

1 year ago

2.4.53

1 year ago

2.2.32

1 year ago

2.4.56

1 year ago

2.4.55

1 year ago

2.2.30

1 year ago

3.7.68

1 year ago

3.7.69

1 year ago

3.7.66

1 year ago

3.7.67

1 year ago

3.7.64

1 year ago

3.7.65

1 year ago

1.1.19

1 year ago

1.1.18

1 year ago

1.1.17

1 year ago

1.1.16

1 year ago

1.1.15

1 year ago

1.1.14

1 year ago

1.1.13

1 year ago

1.1.12

1 year ago

1.1.11

1 year ago

1.1.10

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago