summaryrefslogtreecommitdiff
path: root/lib/_stream_transform.js
Commit message (Collapse)AuthorAgeFilesLines
* stream: make sure 'readable' is emitted before ending the streamMatteo Collina2019-03-271-3/+0
| | | | | | | | 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>
* doc,lib,test: capitalize comment sentencesRuben Bridgewater2018-12-251-3/+3
| | | | | | | | | | | 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>
* tools: capitalize sentencesRuben Bridgewater2018-12-171-2/+2
| | | | | | | | | | | | 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>
* stream: make virtual methods errors consistentLuigi Pinca2018-03-121-1/+1
| | | | | | | | | | | 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>
* lib: port remaining errors to new systemMichaël Zasso2018-03-071-5/+10
| | | | | | | | 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>
* stream: updated streams error handlingMathias Buus2018-03-061-2/+1
| | | | | | | | | | | | | | | | | | | | 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>
* stream: delete unused code陈刚2018-02-021-1/+1
| | | | | | | | | | | | | 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>
* stream: migrate to internal/errorsRuben Bridgewater2017-10-011-1/+1
| | | | | | | 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>
* stream: use more explicit statementsRuben Bridgewater2017-06-291-1/+1
| | | | | | | | | | | | | 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>
* errors: fix and improve error typesRuben Bridgewater2017-06-281-2/+2
| | | | | | | | | | | | | | | | 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>
* errors,stream-transform: migrate to use internal/errors.jssreepurnajasti2017-06-151-5/+4
| | | | | | 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>
* stream: improve Transform performanceBrian White2017-06-131-37/+30
| | | | | | 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>
* stream: improve multiple callback error messagecjihrig2017-05-221-2/+4
| | | | | | | | | | | 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>
* stream: add destroy and _destroy methods.Matteo Collina2017-05-221-0/+8
| | | | | | | | | | | | | 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>
* meta: restore original copyright headerJames M Snell2017-03-101-0/+21
| | | | | | | | | | | | | | | 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.
* src: fixes misplaced commentMadhav Gharmalkar2016-09-301-1/+1
| | | | | | | | | | | 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>
* stream: improve stream error messagesItalo A. Casas2016-09-291-1/+1
| | | | | | | | | | | | | | 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>
* stream: 'data' argument on callback of Transform._flush()Jesús Leganés Combarro "piranna2016-06-091-3/+6
| | | | | | | | | 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>
* stream: prevent object map change in TransformStateEvan Lucas2016-02-021-0/+1
| | | | | | | | | | | 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>
* stream: remove useless if test in transformzoubin2016-01-111-2/+1
| | | | | | | 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>
* lib: Consistent error messages in all modulesmicnic2015-11-091-3/+3
| | | | | | | | 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>
* stream: simpler stream constructonSam Newman2015-02-041-0/+8
| | | | | | | | | | | 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>
* lib: reduce util.is*() usagecjihrig2015-01-311-3/+3
| | | | | | | | | | | | 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>
* lib: use const to define constantscjihrig2015-01-211-2/+2
| | | | | | | | 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>
* Remove excessive copyright/license boilerplateisaacs2015-01-121-22/+0
| | | | | | | 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.
* lib: turn on strict modeBen Noordhuis2014-11-221-0/+2
| | | | | | | | | 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>
* lib: remove unused variablesBrian White2014-06-111-2/+2
| | | | Signed-off-by: Fedor Indutny <fedor@indutny.com>
* lib: remove unused variables and functionsBrian White2013-08-151-2/+1
|
* src: Replace macros with util functionsisaacs2013-08-011-3/+3
|
* lib: macro-ify type checksBen Noordhuis2013-07-241-3/+3
| | | | | Increases the grep factor. Makes it easier to harmonize type checks across the code base.
* stream: objectMode transform should allow falsey valuesJeff Barczewski2013-07-031-1/+1
| | | | | | | | 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.
* Merge remote-tracking branch 'ry/v0.10' into masterisaacs2013-05-171-2/+2
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
| * stream: don't create unnecessary buffers in Readableisaacs2013-05-141-2/+2
| | | | | | | | | | | | | | | | 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.
* | stream: Guarantee ordering of 'finish' eventisaacs2013-05-091-1/+1
|/ | | | | | | | | | | | 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.
* stream: unused variableRafael Garcia2013-04-051-2/+0
|
* stream: remove vestiges of previous _transform APIRafael Garcia2013-04-051-2/+2
|
* stream: Fix stall in Transform under very specific conditionsGil Pedersen2013-03-211-0/+1
| | | | | | | | | | | | | | | | | 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.
* stream: Emit error on stream object, not globalisaacs2013-03-081-1/+1
| | | | | Apparently this function got abstracted out at some point, and 'this' wasn't changed to the correct object.
* stream: Remove bufferSize optionisaacs2013-03-061-2/+2
| | | | | | 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.
* stream: _write takes an encoding argumentisaacs2013-03-051-2/+3
| | | | | This vastly reduces the overhead of decodeStrings:false streams, such as net and http.
* stream: Remove output function from _transformisaacs2013-03-051-19/+21
| | | | Just use stream.push(outputChunk) instead.
* stream: There is no _read cb, there is only pushisaacs2013-02-281-5/+5
| | | | | | | | | | | | | | | | | | | | | | 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.
* stream: Start out in sync=true stateisaacs2013-02-251-0/+5
| | | | | | | | | | | | 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.
* stream: remove lowWaterMark featureisaacs2013-02-211-3/+1
| | | | | | | | | | 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.
* stream: Correct Transform class backpressureisaacs2013-01-281-50/+59
| | | | | | | | | | | | The refactor in b43e544140ccf68580c02e71c56d19b82e1e1d32 to use stream.push() in Transform inadvertently caused it to immediately consume all the written data, regardless of whether or not the readable side was being consumed. Only pull data through the _transform() process when the readable side is being consumed. Fix #4667
* stream: Use push() for Transform._output()isaacs2013-01-101-42/+2
| | | | | | | | | | | This also slightly changes the semantics, in that a 'readable' event may be triggered by the first write() call, even if a user has not yet called read(). This happens because the Transform _write() handler is calling read(0) to start the flow of data. Technically, the new behavior is more 'correct', since it is more in line with the semantics of the 'readable' event in other streams.
* streams2: Remove function.bind() usageisaacs2012-12-131-22/+26
| | | | It's too slow, unfortunately.
* streams2: Add high water mark for Readableisaacs2012-12-131-1/+1
| | | | Also, organize the numeric settings a bit on the ReadableState class
* streams2: ctor guards on Stream classesisaacs2012-12-131-0/+3
|
* streams2: Handle immediate synthetic transforms properlyisaacs2012-12-131-3/+4
|