summaryrefslogtreecommitdiff
path: root/lib/_stream_transform.js
AgeCommit message (Collapse)Author
2019-11-25lib: flatten access to primordialsMichaël Zasso
Store all primordials as properties of the primordials object. Static functions are prefixed by the constructor's name and prototype methods are prefixed by the constructor's name followed by "Prototype". For example: primordials.Object.keys becomes primordials.ObjectKeys. PR-URL: https://github.com/nodejs/node/pull/30610 Refs: https://github.com/nodejs/node/issues/29766 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2019-05-02stream: remove TODO and add a description insteadRuben Bridgewater
After looking into this it turned out that these two errors are sanity checks that should not be reached. It is unfortunate that we assigned error codes for these but changing it into an assertion seems to be a hassle for `readable-streams`. PR-URL: https://github.com/nodejs/node/pull/27086 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com>
2019-04-12lib: enforce the use of Object from primordialsMichaël Zasso
PR-URL: https://github.com/nodejs/node/pull/27146 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gus Caplan <me@gus.host>
2019-03-30benchmark,lib: change var to constRuben Bridgewater
Refs: https://github.com/nodejs/node/pull/26679 PR-URL: https://github.com/nodejs/node/pull/26915 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Refael Ackermann <refack@gmail.com>
2019-03-06stream: make sure 'readable' is emitted before ending the streamMatteo Collina
Fixes: https://github.com/nodejs/node/issues/25810 PR-URL: https://github.com/nodejs/node/pull/26059 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2018-12-17doc,lib,test: capitalize comment sentencesRuben Bridgewater
This activates the eslint capitalize comment rule for comments above 50 characters. PR-URL: https://github.com/nodejs/node/pull/24996 Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2018-12-10tools: capitalize sentencesRuben Bridgewater
This adds the `capitalized-comments` eslint rule to verify that actual sentences use capital letters as starting letters. It ignores special words and all lines below 62 characters. PR-URL: https://github.com/nodejs/node/pull/24808 Reviewed-By: Sam Ruby <rubys@intertwingly.net> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
2018-12-05lib: use ES6 class inheritance styleRuben Bridgewater
PR-URL: https://github.com/nodejs/node/pull/24755 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2018-12-05lib: remove `inherits()` usageRuben Bridgewater
This switches all `util.inherits()` calls to use `Object.setPrototypeOf()` instead. In fact, `util.inherits()` is mainly a small wrapper around exactly this function while adding the `_super` property on the object as well. Refs: #24395 PR-URL: https://github.com/nodejs/node/pull/24755 Refs: https://github.com/nodejs/node/issues/24395 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2018-03-12stream: make virtual methods errors consistentLuigi Pinca
Use the same error code and always emit the error instead of throwing it. PR-URL: https://github.com/nodejs/node/pull/18813 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Michaë Zasso <targos@protonmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2018-03-07lib: port remaining errors to new systemMichaël Zasso
PR-URL: https://github.com/nodejs/node/pull/19137 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2018-03-06stream: updated streams error handlingMathias Buus
This improves error handling for streams in a few ways. 1. It ensures that no user defined methods (_read, _write, ...) are run after .destroy has been called. 2. It introduces an explicit error to tell the user if they are write to write, etc to the stream after it has been destroyed. 3. It makes streams always emit close as the last thing after they have been destroyed 4. Changes the default _destroy to not gracefully end streams. It also updates net, http2, zlib and fs to the new error handling. PR-URL: https://github.com/nodejs/node/pull/18438 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Anna Henningsen <anna@addaleax.net>
2018-02-02stream: delete unused code陈刚
In implementation of `stream.Writable`, `writable._write()` is always called with a callback that is `_writableState.onwrite()`. And In `afterTransform()`, `ts.writechunk` and `ts.writecb` are assigned to null. So, `ts.writecb` is a true value if `ts.writechunk` isn't null. PR-URL: https://github.com/nodejs/node/pull/18278 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
2017-10-01stream: migrate to internal/errorsRuben Bridgewater
PR-URL: https://github.com/nodejs/node/pull/15665 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2017-06-29stream: use more explicit statementsRuben Bridgewater
Using objectMode with stream_wrap has not worked properly before and would end in an error. Therefore prohibit the usage of objectMode alltogether. This also improves the handling performance due to the cheaper chunk check and by using explicit statements as they produce better code from the compiler. PR-URL: https://github.com/nodejs/node/pull/13863 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2017-06-28errors: fix and improve error typesRuben Bridgewater
1) Add missing lazy assert call 2) Remove obsolete error type 3) Name undocumented error type more appropriate 4) Consolidate error type style (rely on util.format instead of using a function) 5) Uppercase the first letter from error messages 6) Improve some internal error parameters PR-URL: https://github.com/nodejs/node/pull/13857 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2017-06-15errors,stream-transform: migrate to use internal/errors.jssreepurnajasti
PR-URL: https://github.com/nodejs/node/pull/13310 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2017-06-13stream: improve Transform performanceBrian White
PR-URL: https://github.com/nodejs/node/pull/13322 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2017-05-22stream: improve multiple callback error messagecjihrig
When a transform stream's callback is called more than once, an error is emitted with a somewhat confusing message. This commit hopes to improve the quality of the error message. Fixes: https://github.com/nodejs/node/issues/12513 PR-URL: https://github.com/nodejs/node/pull/12520 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2017-05-22stream: add destroy and _destroy methods.Matteo Collina
Adds destroy() and _destroy() methods to Readable, Writable, Duplex and Transform. It also standardizes the behavior and the implementation of destroy(), which has been inconsistent in userland and core. This PR also updates all the subsystems of core to use the new destroy(). PR-URL: https://github.com/nodejs/node/pull/12925 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Calvin Metcalf <calvin.metcalf@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-03-10meta: restore original copyright headerJames M Snell
A prior io.js era commit inappropriately removed the original copyright statements from the source. This restores those in any files still remaining from that edit. Ref: https://github.com/nodejs/TSC/issues/174 Ref: https://github.com/nodejs/node/pull/10599 PR-URL: https://github.com/nodejs/node/pull/10155 Note: This PR was required, reviewed-by and approved by the Node.js Foundation Legal Committee and the TSC. There is no `Approved-By:` meta data.
2016-09-30src: fixes misplaced commentMadhav Gharmalkar
In e26622b, a comment was incorrectly moved from the code it was describing. Fixes: https://github.com/nodejs/node/issues/8856 PR-URL: https://github.com/nodejs/node/pull/8860 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2016-09-29stream: improve stream error messagesItalo A. Casas
Improve message when tranform._transform() method is not implemented Improve error message when Readable._read() is not implemented Remove extra word in err msg when Writable._write() when not implemented Remove extra word in err msg when Transform._transform() when not implemented PR-URL: https://github.com/nodejs/node/pull/8801 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
2016-06-09stream: 'data' argument on callback of Transform._flush()Jesús Leganés Combarro "piranna
Add a `data` argument on Transform._flush() callback to be API consistent with Transform._transform(). Fixes: https://github.com/nodejs/node/issues/3707 PR-URL: https://github.com/nodejs/node/pull/3708 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2016-02-02stream: prevent object map change in TransformStateEvan Lucas
TransformState has the writeencoding property that gets set on the first _write. It is not declared when the transform state is initially constructed and can cause a deopt. PR-URL: https://github.com/nodejs/node/pull/5032 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-01-11stream: remove useless if test in transformzoubin
PR-URL: https://github.com/nodejs/node/pull/4617 Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
2015-11-09lib: Consistent error messages in all modulesmicnic
This commit fixes some error messages that are not consistent with some general rules which most of the error messages follow. PR-URL: https://github.com/nodejs/node/pull/3374 Reviewed-By: Roman Reiss <me@silverwind.io>
2015-02-04stream: simpler stream constructonSam Newman
Adds simplified constructor pattern, allowing users to provide "read", "write", "transform", "flush", and "writev" functions as stream options in lieu of subclassing. Semver: minor PR-URL: https://github.com/iojs/io.js/pull/697 Fixes: https://github.com/iojs/readable-stream/issues/102 Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
2015-01-31lib: reduce util.is*() usagecjihrig
Many of the util.is*() methods used to check data types simply compare against a single value or the result of typeof. This commit replaces calls to these methods with equivalent checks. This commit does not touch calls to the more complex methods (isRegExp(), isDate(), etc.). Fixes: https://github.com/iojs/io.js/issues/607 PR-URL: https://github.com/iojs/io.js/pull/647 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-21lib: use const to define constantscjihrig
This commit replaces a number of var statements throughout the lib code with const statements. PR-URL: https://github.com/iojs/io.js/pull/541 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-12Remove excessive copyright/license boilerplateisaacs
The copyright and license notice is already in the LICENSE file. There is no justifiable reason to also require that it be included in every file, since the individual files are not individually distributed except as part of the entire package.
2014-11-22lib: turn on strict modeBen Noordhuis
Turn on strict mode for the files in the lib/ directory. It helps catch bugs and can have a positive effect on performance. PR-URL: https://github.com/node-forward/node/pull/64 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Fedor Indutny <fedor@indutny.com>
2014-06-11lib: remove unused variablesBrian White
Signed-off-by: Fedor Indutny <fedor@indutny.com>
2013-08-15lib: remove unused variables and functionsBrian White
2013-08-01src: Replace macros with util functionsisaacs
2013-07-24lib: macro-ify type checksBen Noordhuis
Increases the grep factor. Makes it easier to harmonize type checks across the code base.
2013-07-03stream: objectMode transform should allow falsey valuesJeff Barczewski
If a transform stream has objectMode = true, it should allow falsey values other than (null) like 0, false, ''. null is reserved to indicate stream eof but other falsey values should flow through properly.
2013-05-17Merge remote-tracking branch 'ry/v0.10' into masterisaacs
Conflicts: AUTHORS ChangeLog deps/uv/ChangeLog deps/uv/config-unix.mk deps/uv/src/unix/stream.c deps/uv/src/version.c deps/uv/uv.gyp src/node.cc src/node_buffer.cc src/node_crypto.cc src/node_version.h src/stream_wrap.cc src/stream_wrap.h
2013-05-14stream: don't create unnecessary buffers in Readableisaacs
If there is an encoding, and we do 'stream.push(chunk, enc)', and the encoding argument matches the stated encoding, then we're converting from a string, to a buffer, and then back to a string. Of course, this is a completely pointless bit of work, so it's best to avoid it when we know that we can do so safely.
2013-05-09stream: Guarantee ordering of 'finish' eventisaacs
In synchronous Writable streams (where the _write cb is called on the current tick), the 'finish' event (and thus the end() callback) can in some cases be called before all the write() callbacks are called. Use a counter, and have stream.Transform rely on the 'prefinish' event instead of the 'finish' event. This has zero effect on most streams, but it corrects an edge case and makes it perform more deterministically, which is a Good Thing.
2013-04-05stream: unused variableRafael Garcia
2013-04-05stream: remove vestiges of previous _transform APIRafael Garcia
2013-03-21stream: Fix stall in Transform under very specific conditionsGil Pedersen
The stall is exposed in the test, though the test itself asserts before it stalls. The test is constructed to replicate the stalling state of a complex Passthrough usecase since I was not able to reliable trigger the stall. Some of the preconditions for triggering the stall are: * rs.length >= rs.highWaterMark * !rs.needReadable * _transform() handler that can return empty transforms * multiple sync write() calls Combined this can trigger a case where rs.reading is not cleared when further progress requires this. The fix is to always clear rs.reading.
2013-03-08stream: Emit error on stream object, not globalisaacs
Apparently this function got abstracted out at some point, and 'this' wasn't changed to the correct object.
2013-03-06stream: Remove bufferSize optionisaacs
Now that highWaterMark increases when there are large reads, this greatly reduces the number of calls necessary to _read(size), assuming that _read actually respects the size argument.
2013-03-05stream: _write takes an encoding argumentisaacs
This vastly reduces the overhead of decodeStrings:false streams, such as net and http.
2013-03-05stream: Remove output function from _transformisaacs
Just use stream.push(outputChunk) instead.
2013-02-28stream: There is no _read cb, there is only pushisaacs
This makes it so that `stream.push(chunk)` is the only way to signal the end of reading, removing the confusing disparity between the callback-style _read method, and the fact that most real-world streams do not have a 1:1 corollation between the "please give me data" event, and the actual arrival of a chunk of data. It is still possible, of course, to implement a `CallbackReadable` on top of this. Simply provide a method like this as the callback: function readCallback(er, chunk) { if (er) stream.emit('error', er); else stream.push(chunk); } However, *only* fs streams actually would behave in this way, so it makes not a lot of sense to make TCP, TLS, HTTP, and all the rest have to bend into this uncomfortable paradigm.
2013-02-25stream: Start out in sync=true stateisaacs
The Readable and Writable classes will nextTick certain things if in sync mode. The sync flag gets unset after a call to _read or _write. However, most of these behaviors should also be deferred until nextTick if no reads have been made (for example, the automatic '_read up to hwm' behavior on Readable.push(chunk)) Set the sync flag to true in the constructor, so that it will not trigger an immediate 'readable' event, call to _read, before the user has had a chance to set a _read method implementation.
2013-02-21stream: remove lowWaterMark featureisaacs
It seems like a good idea on the face of it, but lowWaterMarks are actually not useful, and in practice should always be set to zero. It would be worthwhile for writers if we actually did some kind of writev() type of thing, but actually this just delays calling write() and the overhead of doing a bunch of Buffer copies is not worth the slight benefit of calling write() fewer times.