Skip to content

Commit

Permalink
Update bare-stream
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperisager committed May 31, 2024
1 parent 244f9cb commit ae5534a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
24 changes: 9 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,11 @@ exports.ReadStream = class TTYReadStream extends Readable {
return this.setMode(mode ? constants.mode.RAW : constants.mode.NORMAL)
}

_read (cb) {
_read () {
if ((this._state & constants.state.READING) === 0) {
this._state |= constants.state.READING
binding.resume(this._handle)
}

cb(null)
}

_predestroy () {
Expand All @@ -60,8 +58,8 @@ exports.ReadStream = class TTYReadStream extends Readable {
TTYReadStream._streams.delete(this)
}

_destroy (cb) {
if (this._state & constants.state.CLOSING) return cb(null)
_destroy (err, cb) {
if (this._state & constants.state.CLOSING) return cb(err)
this._state |= constants.state.CLOSING
this._pendingDestroy = cb
binding.close(this._handle)
Expand Down Expand Up @@ -106,7 +104,7 @@ exports.ReadStream = class TTYReadStream extends Readable {

exports.WriteStream = class TTYWriteStream extends Writable {
constructor (fd, opts = {}) {
super({ mapWritable })
super()

this._state = 0

Expand All @@ -130,9 +128,9 @@ exports.WriteStream = class TTYWriteStream extends Writable {
return binding.getWindowSize(this._handle)
}

_writev (datas, cb) {
this._pendingWrite = [cb, datas]
binding.writev(this._handle, datas)
_writev (batch, cb) {
this._pendingWrite = [cb, batch]
binding.writev(this._handle, batch.map(({ chunk }) => chunk))
}

_predestroy () {
Expand All @@ -142,8 +140,8 @@ exports.WriteStream = class TTYWriteStream extends Writable {
TTYWriteStream._streams.delete(this)
}

_destroy (cb) {
if (this._state & constants.state.CLOSING) return cb(null)
_destroy (err, cb) {
if (this._state & constants.state.CLOSING) return cb(err)
this._state |= constants.state.CLOSING
this._pendingDestroy = cb
binding.close(this._handle)
Expand Down Expand Up @@ -196,7 +194,3 @@ Bare
const empty = Buffer.alloc(0)

function noop () {}

function mapWritable (buf) {
return typeof buf === 'string' ? Buffer.from(buf) : buf
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"homepage": "https://github.com/holepunchto/bare-tty#readme",
"dependencies": {
"bare-events": "^2.2.0",
"bare-stream": "^1.0.0"
"bare-stream": "^2.0.0"
},
"devDependencies": {
"brittle": "^3.2.1",
Expand Down

0 comments on commit ae5534a

Please sign in to comment.