bindSource (source) { debuglog(`BIND ${this.name} to ${source}`) source.bindSink(this) this.source = source return this }
debuglog(JSON.stringify(p,null,2));
_final (cb) { debuglog(`_FINAL ${this.name}`) this[kEnded] = true if (this[kPulling]) { // Called when a chain of Steams3 streams closes, so send an 'end'. this.sink.next(Status.end, null, Buffer.alloc(0), 0) cb() } else { // Hope that a pull is made... this[kFinalCallback] = cb } }
_write (chunk, encoding, callback) { debuglog(`_WRITE ${this.name}`, arguments) if (this[kWriteCallback] !== null) { throw new Error('_write called again before callback was called') } if (this[kEnded]) { if (this[kFinalCallback] === null) { // _write should not have happened. const error = new Error('write happened but stream was ended without a final callback') this.destory(error) } return } if (!Buffer.isBuffer(chunk)) { const encoding = this._readableState.encoding || this._readableState.defaultEncoding chunk = Buffer.from(chunk, encoding) } // Store callback so we can call it when pull is called. this[kWriteCallback] = callback this[kPulling] = false // Send data to our sink. this.sink.next(Status.continue, null, chunk, chunk.length) }
var item = obj.nitro.results.items[i]; debuglog(item);
_destroy (err, cb) { debuglog(`_DESTROY ${this.name}`, arguments) if (this[kDestroyCallback] !== null) { throw new Error('ReadableSink: _destroy called twice') } this[kDestroyCallback] = cb this[kErrored] = true if (err) { // If there is an error and we have a source, we want to propogate // the error upwards so all sources can close. // Store the callback for when the error returns to this component. this.source.pull(err) } else { // No error, but need to propogate a forced close anyways. // XXX(Fishrock): Does BOB need to support propogating a close upwards due to Streams3? // XXX(Fishrock): Use extension-stop? this.source.pull(new Error('ReadableSink: user called stream.destroy()')) } }
pull (error, buffer) { debuglog(`PULL ${this.name}`, arguments, this[kWriteCallback])
_read (size) { debuglog(`_READ ${this.name}`, arguments) // Allocate a sized buffer and pull. // (Since pull() does not presently have any 'size' argument.) this.source.pull(null, Buffer.alloc(size)) }
_destroy (err, cb) { debuglog(`_DESTROY ${this.name}`, arguments) if (this[kDestroyCallback] !== null) { throw new Error('_destroy called twice') } this[kDestroyCallback] = cb this[kEnding] = true if (err) { this[kErrored] = true // If there is an error and we have a source, we want to propogate // the error upwards so all sources can close. // Store the callback for when the error returns to this component. this.sink.next(Status.error, err, Buffer.alloc(0), 0) } // Otherwise wait for _final (?) }