Update Files

This commit is contained in:
2025-01-22 16:18:30 +01:00
parent ed4603cf95
commit a36294b518
16718 changed files with 2960346 additions and 0 deletions

View File

@ -0,0 +1,344 @@
/*
* Copyright (C)2014-2020 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package js.node.stream;
import haxe.extern.EitherType;
import js.node.events.EventEmitter.Event;
import js.node.stream.Readable.IReadable;
import js.node.stream.Writable.IWritable;
#if haxe4
import js.lib.Error;
#else
import js.Error;
#end
/**
Writable streams are an abstraction for a destination to which data is written.
@see https://nodejs.org/api/stream.html#stream_writable_streams
**/
@:enum abstract DuplexEvent<T:haxe.Constraints.Function>(Event<T>) to Event<T> {
// Writable stream events -------------------------------------------------
// var Close:DuplexEvent<Void->Void> = "close";
/**
If a call to stream.write(chunk) returns `false`, the `'drain'` event will be emitted
when it is appropriate to resume writing data to the stream.
@see https://nodejs.org/api/stream.html#stream_event_drain
**/
var Drain:DuplexEvent<Void->Void> = "drain";
// var Error:DuplexEvent<Error->Void> = "error";
/**
The `'finish'` event is emitted after the stream.end() method has been called,
and all data has been flushed to the underlying system.
@see https://nodejs.org/api/stream.html#stream_event_finish
**/
var Finish:DuplexEvent<Void->Void> = "finish";
/**
The `'pipe'` event is emitted when the stream.pipe() method is called on a readable stream,
adding this writable to its set of destinations.
@see https://nodejs.org/api/stream.html#stream_event_pipe
**/
var Pipe:DuplexEvent<IReadable->Void> = "pipe";
/**
The `'unpipe'` event is emitted when the stream.unpipe() method is called on a Readable stream,
removing this Writable from its set of destinations.
@see https://nodejs.org/api/stream.html#stream_event_unpipe
**/
var Unpipe:DuplexEvent<IReadable->Void> = "unpipe";
// Readable stream events -------------------------------------------------
// var Close:DuplexEvent<Void->Void> = "close";
/**
The `'data'` event is emitted whenever the stream is relinquishing ownership of
a chunk of data to a consumer. This may occur whenever the stream is switched
in flowing mode by calling `readable.pipe()`, `readable.resume()`, or by
attaching a listener callback to the `'data'` event. The `'data'` event will
also be emitted whenever the `readable.read()` method is called and a chunk of
data is available to be returned.
@see https://nodejs.org/api/stream.html#stream_event_data
**/
var Data:DuplexEvent<Dynamic->Void> = "data";
/**
The `'end'` event is emitted when there is no more data to be consumed from
the stream.
@see https://nodejs.org/api/stream.html#stream_event_end
**/
var End:DuplexEvent<Void->Void> = "end";
// var Error:DuplexEvent<Error->Void> = "error";
/**
The `'pause'` event is emitted when `stream.pause()` is called
and `readableFlowing` is not `false`.
@see https://nodejs.org/api/stream.html#stream_event_pause
**/
var Pause:DuplexEvent<Void->Void> = "pause";
/**
The `'readable'` event is emitted when there is data available to be read from
the stream. In some cases, attaching a listener for the `'readable'` event will
cause some amount of data to be read into an internal buffer.
@see https://nodejs.org/api/stream.html#stream_event_readable
**/
var Readable:DuplexEvent<Void->Void> = "readable";
/**
The `'resume'` event is emitted when `stream.resume()` is
called and `readableFlowing` is not `true`.
@see https://nodejs.org/api/stream.html#stream_event_resume
**/
var Resume:DuplexEvent<Void->Void> = "resume";
// Overlapped events ------------------------------------------------------
/**
The `'close'` event is emitted when the stream and any of its underlying
resources (a file descriptor, for example) have been closed.
The event indicates that no more events will be emitted, and no further computation will occur.
@see https://nodejs.org/api/stream.html#stream_event_close
@see https://nodejs.org/api/stream.html#stream_event_close_1
**/
var Close:DuplexEvent<Void->Void> = "close";
/**
@see https://nodejs.org/api/stream.html#stream_event_error
@see https://nodejs.org/api/stream.html#stream_event_error_1
**/
var Error:DuplexEvent<Error->Void> = "error";
}
/**
Duplex streams are streams that implement both the `Readable` and `Writable` interfaces.
@see https://nodejs.org/api/stream.html#stream_class_stream_duplex
**/
@:jsRequire("stream", "Duplex")
extern class Duplex<TSelf:Duplex<TSelf>> extends Readable<TSelf> implements IDuplex {
// --------- Writable interface implementation ----------------------------
/**
The `writable.cork()` method forces all written data to be buffered in memory.
The buffered data will be flushed when either the `stream.uncork()` or `stream.end()` methods are called.
@see https://nodejs.org/api/stream.html#stream_writable_cork
**/
function cork():Void;
// This field is defined in super class.
// function destroy(?error:Error):TSelf;
// var destroyed(default, null):Bool;
/**
Calling the `writable.end()` method signals that no more data will be written to the Writable.
The optional `chunk` and `encoding` arguments allow one final additional chunk of data to be written immediately before closing the stream.
If provided, the optional `callback` function is attached as a listener for the 'finish' event.
@see https://nodejs.org/api/stream.html#stream_writable_end_chunk_encoding_callback
**/
@:overload(function(?callback:EitherType<Void->Void, Null<Error>->Void>):Void {})
function end(chunk:Dynamic, ?encoding:String, ?callback:EitherType<Void->Void, Null<Error>->Void>):Void;
/**
The `writable.setDefaultEncoding()` method sets the default `encoding` for a Writable stream.
@see https://nodejs.org/api/stream.html#stream_writable_setdefaultencoding_encoding
**/
function setDefaultEncoding(encoding:String):TSelf;
/**
The `writable.uncork()` method flushes all data buffered since `stream.cork()` was called.
@see https://nodejs.org/api/stream.html#stream_writable_uncork
**/
function uncork():Void;
/**
Is `true` if it is safe to call `writable.write()`.
@see https://nodejs.org/api/stream.html#stream_writable_writable
**/
var writable(default, null):Bool;
/**
Is `true` after `writable.end()` has been called. This property
does not indicate whether the data has been flushed, for this use
`writable.writableFinished` instead.
@see https://nodejs.org/api/stream.html#stream_writable_writableended
**/
var writableEnded(default, null):Bool;
/**
Is set to `true` immediately before the 'finish' event is emitted.
@see https://nodejs.org/api/stream.html#stream_writable_writablefinished
**/
var writableFinished(default, null):Bool;
/**
Return the value of `highWaterMark` passed when constructing this `Writable`.
@see https://nodejs.org/api/stream.html#stream_writable_writablehighwatermark
**/
var writablehighWaterMark(default, null):Int;
/**
This property contains the number of bytes (or objects) in the queue ready to be written.
The value provides introspection data regarding the status of the `highWaterMark`.
@see https://nodejs.org/api/stream.html#stream_writable_writablelength
**/
var writableLength(default, null):Int;
/**
Getter for the property `objectMode` of a given `Writable` stream.
@see https://nodejs.org/api/stream.html#stream_writable_writableobjectmode
**/
var writableObjectMode(default, null):Bool;
/**
The `writable.write()` method writes some data to the stream, and calls the supplied `callback` once the data has been fully handled.
If an error occurs, the `callback` may or may not be called with the error as its first argument.
To reliably detect write errors, add a listener for the `'error'` event.
@see https://nodejs.org/api/stream.html#stream_writable_write_chunk_encoding_callback
**/
function write(chunk:Dynamic, ?encoding:String, ?callback:EitherType<Void->Void, Null<Error>->Void>):Bool;
// --------- API for implementing a Writable Stream -----------------------
// function new(?options:DuplexNewOptions);
/**
All `Writable` stream implementations must provide a `writable._write()` method to send data to the underlying resource.
@see https://nodejs.org/api/stream.html#stream_writable_write_chunk_encoding_callback_1
**/
private function _write(chunk:Dynamic, encoding:String, callback:Null<Error>->Void):Void;
/**
This function MUST NOT be called by application code directly.
It should be implemented by child classes, and called by the internal `Writable` class methods only.
@see https://nodejs.org/api/stream.html#stream_writable_writev_chunks_callback
**/
private function _writev(chunks:Array<Writable.Chunk>, callback:Null<Error>->Void):Void;
// This field is defined in super class.
// private function _destroy(err:Null<Error>, ?callback:Null<Error>->Void):Void;
/**
The `_final()` method must not be called directly.
t may be implemented by child classes, and if so, will be called by the internal `Writable` class methods only.
@see https://nodejs.org/api/stream.html#stream_writable_final_callback
**/
private function _final(callback:Null<Error>->Void):Void;
// --------- Overlapped interface -----------------------------------------
/**
Destroy the stream.
Optionally emit an `'error'` event, and emit a `'close'` event unless `emitClose` is set in `false`.
@see https://nodejs.org/api/stream.html#stream_writable_destroy_error
@see https://nodejs.org/api/stream.html#stream_readable_destroy_error
**/
override function destroy(?error:Error):TSelf;
// This field is defined in super class.
// var destroyed(default, null):Bool;
/**
@see https://nodejs.org/api/stream.html#stream_constructor_new_stream_writable_options
@see https://nodejs.org/api/stream.html#stream_new_stream_readable_options
**/
function new(?options:DuplexNewOptions);
/**
The `_destroy()` method is called by `destroy()`.
It can be overridden by child classes but it **must not** be called directly.
@see https://nodejs.org/api/stream.html#stream_writable_destroy_err_callback
@see https://nodejs.org/api/stream.html#stream_readable_destroy_err_callback
**/
private override function _destroy(err:Null<Error>, callback:Null<Error>->Void):Void;
// This field is defined in super class.
// var isTTY(default, null):Bool;
}
/**
Passed to both `Writable` and `Readable` constructors. Also has the following fields:
@see https://nodejs.org/api/stream.html#stream_new_stream_duplex_options
**/
typedef DuplexNewOptions = {
> Readable.ReadableNewOptions,
> Writable.WritableNewOptions,
/**
If set to `false`, then the stream will automatically end the writable side when the readable side ends. Default: `true`.
**/
@:optional var allowHalfOpen:Bool;
/**
Sets `objectMode` for readable side of the stream. Has no effect if `objectMode` is `true`. Default: `false`.
**/
@:optional var readableObjectMode:Bool;
/**
Sets `objectMode` for writable side of the stream. Has no effect if `objectMode` is `true`. Default: `false`.
**/
@:optional var writableObjectMode:Bool;
/**
Sets `highWaterMark` for the readable side of the stream. Has no effect if `highWaterMark` is provided.
**/
@:optional var readableHighWaterMark:Int;
/**
Sets `highWaterMark` for the writable side of the stream. Has no effect if `highWaterMark` is provided.
**/
@:optional var writableHighWaterMark:Int;
}
@:remove
extern interface IDuplex extends IReadable extends IWritable {}

View File

@ -0,0 +1,36 @@
/*
* Copyright (C)2014-2020 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package js.node.stream;
/**
The `stream.PassThrough` class is a trivial implementation of a `Transform` stream
that simply passes the input bytes across to the output.
Its purpose is primarily for examples and testing, but there are some use cases
where `stream.PassThrough` is useful as a building block for novel sorts of streams.
@see https://nodejs.org/api/stream.html#stream_class_stream_passthrough
**/
@:jsRequire("stream", "PassThrough")
extern class PassThrough extends Transform<PassThrough> {
function new();
}

View File

@ -0,0 +1,386 @@
/*
* Copyright (C)2014-2020 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package js.node.stream;
import js.node.Iterator;
import js.node.Stream;
import js.node.events.EventEmitter.Event;
import js.node.stream.Writable.IWritable;
#if haxe4
import js.lib.Error;
#else
import js.Error;
#end
/**
Readable streams are an abstraction for a source from which data is consumed.
@see https://nodejs.org/api/stream.html#stream_readable_streams
**/
@:enum abstract ReadableEvent<T:haxe.Constraints.Function>(Event<T>) to Event<T> {
/**
The `'close'` event is emitted when the stream and any of its underlying
resources (a file descriptor, for example) have been closed.
The event indicates that no more events will be emitted, and no further computation will occur.
@see https://nodejs.org/api/stream.html#stream_event_close_1
**/
var Close:ReadableEvent<Void->Void> = "close";
/**
The `'data'` event is emitted whenever the stream is relinquishing ownership of
a chunk of data to a consumer. This may occur whenever the stream is switched
in flowing mode by calling `readable.pipe()`, `readable.resume()`, or by
attaching a listener callback to the `'data'` event. The `'data'` event will
also be emitted whenever the `readable.read()` method is called and a chunk of
data is available to be returned.
@see https://nodejs.org/api/stream.html#stream_event_data
**/
var Data:ReadableEvent<Dynamic->Void> = "data";
/**
The `'end'` event is emitted when there is no more data to be consumed from
the stream.
@see https://nodejs.org/api/stream.html#stream_event_end
**/
var End:ReadableEvent<Void->Void> = "end";
/**
The `'error'` event may be emitted by a `Readable` implementation at any time.
Typically, this may occur if the underlying stream is unable to generate data
due to an underlying internal failure, or when a stream implementation attempts
to push an invalid chunk of data.
@see https://nodejs.org/api/stream.html#stream_event_error_1
**/
var Error:ReadableEvent<Error->Void> = "error";
/**
The `'pause'` event is emitted when `stream.pause()` is called
and `readableFlowing` is not `false`.
@see https://nodejs.org/api/stream.html#stream_event_pause
**/
var Pause:ReadableEvent<Void->Void> = "pause";
/**
The `'readable'` event is emitted when there is data available to be read from
the stream. In some cases, attaching a listener for the `'readable'` event will
cause some amount of data to be read into an internal buffer.
@see https://nodejs.org/api/stream.html#stream_event_readable
**/
var Readable:ReadableEvent<Void->Void> = "readable";
/**
The `'resume'` event is emitted when `stream.resume()` is
called and `readableFlowing` is not `true`.
@see https://nodejs.org/api/stream.html#stream_event_resume
**/
var Resume:ReadableEvent<Void->Void> = "resume";
}
/**
@see https://nodejs.org/api/stream.html#stream_class_stream_readable
**/
@:jsRequire("stream", "Readable")
extern class Readable<TSelf:Readable<TSelf>> extends Stream<TSelf> implements IReadable {
/**
Destroy the stream. Optionally emit an `'error'` event, and emit a `'close'` event unless `emitClose` is set in `false`.
After this call, the readable stream will release any internal resources and subsequent calls to `push()` will be ignored.
Implementors should not override this method, but instead implement `readable._destroy()`.
@see https://nodejs.org/api/stream.html#stream_readable_destroy_error
**/
function destroy(?error:Error):TSelf;
/**
Is `true` after `readable.destroy()` has been called.
@see https://nodejs.org/api/stream.html#stream_readable_destroyed
**/
var destroyed(default, null):Bool;
/**
The `readable.isPaused()` method returns the current operating state of the `Readable`.
This is used primarily by the mechanism that underlies the `readable.pipe()` method.
In most typical cases, there will be no reason to use this method directly.
@see https://nodejs.org/api/stream.html#stream_readable_ispaused
**/
function isPaused():Bool;
/**
The `readable.pause()` method will cause a stream in flowing mode to stop emitting `'data'` events,
switching out of flowing mode. Any data that becomes available will remain in the internal buffer.
@see https://nodejs.org/api/stream.html#stream_readable_pause
**/
function pause():TSelf;
/**
The `readable.pipe()` method attaches a `Writable` stream to the `readable`,
causing it to switch automatically into flowing mode and push all of its data to the attached `Writable`.
The flow of data will be automatically managed so that the destination `Writable` stream
is not overwhelmed by a faster `Readable` stream.
@see https://nodejs.org/api/stream.html#stream_readable_pipe_destination_options
**/
function pipe<T:IWritable>(destination:T, ?options:{?end:Bool}):T;
/**
The `readable.read()` method pulls some data out of the internal buffer and returns it.
If no data available to be read, `null` is returned. By default,
the data will be returned as a `Buffer` object unless an encoding has been specified using
the `readable.setEncoding()` method or the stream is operating in object mode.
@see https://nodejs.org/api/stream.html#stream_readable_read_size
**/
function read(?size:Int):Null<Dynamic>;
/**
Is `true` if it is safe to call `readable.read()`.
@see https://nodejs.org/api/stream.html#stream_readable_readable
**/
var readable(default, null):Bool;
/**
Getter for the property `encoding` of a given `Readable` stream.
The `encoding` property can be set using the `readable.setEncoding()` method.
@see https://nodejs.org/api/stream.html#stream_readable_readableencoding
**/
var readableEncoding(default, null):Null<String>;
/**
Becomes `true` when `'end'` event is emitted.
@see https://nodejs.org/api/stream.html#stream_readable_readableended
**/
var readableEnded(default, null):Bool;
/**
Returns the value of `highWaterMark` passed when constructing this `Readable`.
@see https://nodejs.org/api/stream.html#stream_readable_readablehighwatermark
**/
var readableHighWaterMark(default, null):Int;
/**
This property contains the number of bytes (or objects) in the queue ready to be read.
The value provides introspection data regarding the status of the `highWaterMark`.
@see https://nodejs.org/api/stream.html#stream_readable_readablelength
**/
var readableLength(default, null):Int;
/**
Getter for the property `objectMode` of a given `Readable` stream.
@see https://nodejs.org/api/stream.html#stream_readable_readableobjectmode
**/
var readableObjectMode(default, null):Bool;
/**
The `readable.resume()` method causes an explicitly paused `Readable` stream to resume emitting `'data'` events,
switching the stream into flowing mode.
@see https://nodejs.org/api/stream.html#stream_readable_resume
**/
function resume():TSelf;
/**
The `readable.setEncoding()` method sets the character encoding for data read from the `Readable` stream.
@see https://nodejs.org/api/stream.html#stream_readable_setencoding_encoding
**/
function setEncoding(encoding:String):TSelf;
/**
The `readable.unpipe()` method detaches a `Writable` stream previously attached using the `stream.pipe()` method.
@see https://nodejs.org/api/stream.html#stream_readable_unpipe_destination
**/
function unpipe(?destination:IWritable):TSelf;
/**
Passing `chunk` as `null` signals the end of the stream (EOF), after which no more data can be written.
@see https://nodejs.org/api/stream.html#stream_readable_unshift_chunk_encoding
**/
function unshift(chunk:Null<Dynamic>, ?encoding:String):Void;
/**
Prior to Node.js 0.10, streams did not implement the entire `stream` module API as it is currently defined.
(See Compatibility for more information.)
@see https://nodejs.org/api/stream.html#stream_readable_wrap_stream
**/
function wrap(stream:Dynamic):IReadable;
// --------- API for implementing a Readable Stream -----------------------
/**
@see https://nodejs.org/api/stream.html#stream_new_stream_readable_options
**/
function new(?options:ReadableNewOptions);
/**
This function **MUST NOT** be called by application code directly.
It should be implemented by child classes, and called by the internal `Readable` class methods only.
@see https://nodejs.org/api/stream.html#stream_readable_read_size_1
**/
private function _read(size:Int):Void;
/**
The `_destroy()` method is called by `readable.destroy()`.
It can be overridden by child classes but it **must not** be called directly.
@see https://nodejs.org/api/stream.html#stream_readable_destroy_err_callback
**/
private function _destroy(err:Null<Error>, callback:Null<Error>->Void):Void;
/**
The `readable.push()` method is intended be called only by `Readable` implementers,
and only from within the `readable._read()` method.
@see https://nodejs.org/api/stream.html#stream_readable_push_chunk_encoding
**/
private function push(chunk:Null<Dynamic>, ?encoding:String):Bool;
// --------- TTY module API ----------------------------------------------
/**
Terminal read streams (i.e. process.stdin) have this property set to true.
It is false for any other read streams.
@see https://nodejs.org/api/tty.html#tty_readstream_istty
**/
var isTTY(default, null):Bool;
// --------- static API --------------------------------------------------
// TODO @:overload(function<T>(iterable:AsyncIterator<T>, ?options:ReadableNewOptions):IReadable {})
static function from<T>(iterable:Iterator<T>, ?options:ReadableNewOptions):IReadable;
}
/**
Options for `Readable` private constructor.
For stream implementors only, see node.js API documentation
**/
typedef ReadableNewOptions = {
/**
The maximum number of bytes to store in the internal buffer before ceasing to read from the underlying resource.
Default: `16384` (16kb), or `16` for `objectMode` streams.
**/
@:optional var highWaterMark:Int;
/**
If specified, then buffers will be decoded to strings using the specified encoding.
Default: `null`.
**/
@:optional var encoding:String;
/**
Whether this stream should behave as a stream of objects.
Meaning that `stream.read(n)` returns a single value instead of a `Buffer` of size `n`.
Default: `false`.
**/
@:optional var objectMode:Bool;
/**
Whether or not the stream should emit `'close'` after it has been destroyed.
Default: `true`.
**/
@:optional var emitClose:Bool;
/**
Implementation for the `stream._read()` method.
**/
#if haxe4
@:optional var read:(size:Int) -> Void;
#else
@:optional var read:Int->Void;
#end
/**
Implementation for the `stream._destroy()` method.
**/
#if haxe4
@:optional var destroy:(err:Null<Error>, callback:Null<Error>->Void) -> Void;
#else
@:optional var destroy:Null<Error>->(Null<Error>->Void)->Void;
#end
/**
Whether this stream should automatically call `.destroy()` on itself after ending.
Default: `false`.
**/
@:optional var autoDestroy:Bool;
}
/**
`IReadable` interface is used as "any Readable".
See `Readable` for actual class documentation.
**/
@:remove
extern interface IReadable extends IStream {
function destroy(?error:Error):IReadable;
var destroyed(default, null):Bool;
function isPaused():Bool;
function pause():IReadable;
function pipe<T:IWritable>(destination:T, ?options:{?end:Bool}):T;
function read(?size:Int):Null<Dynamic>;
var readable(default, null):Bool;
var readableEncoding(default, null):Null<String>;
var readableEnded(default, null):Bool;
var readableHighWaterMark(default, null):Int;
var readableLength(default, null):Int;
var readableObjectMode(default, null):Bool;
function resume():IReadable;
function setEncoding(encoding:String):IReadable;
function unpipe(?destination:IWritable):IReadable;
function unshift(chunk:Null<Dynamic>, ?encoding:String):Void;
function wrap(stream:Dynamic):IReadable;
}

View File

@ -0,0 +1,84 @@
/*
* Copyright (C)2014-2020 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package js.node.stream;
#if haxe4
import js.lib.Error;
#else
import js.Error;
#end
/**
A `Transform` stream is a `Duplex` stream where the output is computed in some way from the input.
Examples include `zlib` streams or `crypto` streams that compress, encrypt, or decrypt data.
@see https://nodejs.org/api/stream.html#stream_implementing_a_transform_stream
**/
@:jsRequire("stream", "Transform")
extern class Transform<TSelf:Transform<TSelf>> extends Duplex<TSelf> implements ITransform {
function new(?options:TransformNewOptions);
/**
This function **MUST NOT** be called by application code directly.
It should be implemented by child classes, and called by the internal `Readable` class methods only.
@see https://nodejs.org/api/stream.html#stream_transform_flush_callback
**/
private function _flush(callback:Null<Error>->Void):Void;
/**
This function **MUST NOT** be called by application code directly.
It should be implemented by child classes, and called by the internal `Readable` class methods only.
@see https://nodejs.org/api/stream.html#stream_transform_transform_chunk_encoding_callback
**/
#if haxe4
private function _transform(chunk:Dynamic, encoding:String, callback:(error:Null<Error>, data:Dynamic) -> Void):Void;
#else
private function _transform(chunk:Dynamic, encoding:String, callback:Null<Error>->Dynamic->Void):Void;
#end
}
/**
@see https://nodejs.org/api/stream.html#stream_new_stream_transform_options
**/
typedef TransformNewOptions = {
> Duplex.DuplexNewOptions,
/**
Implementation for the `stream._transform()` method.
**/
#if haxe4
@:optional var transform:(chunk:Dynamic, encoding:String, callback:(error:Null<Error>, data:Dynamic) -> Void) -> Void;
#else
@:optional var transform:Dynamic->String->(Null<Error>->Dynamic->Void)->Void;
#end
/**
Implementation for the `stream._flush()` method.
**/
@:optional var flush:Null<Error>->Void;
}
@:remove
extern interface ITransform extends Duplex.IDuplex {}

View File

@ -0,0 +1,396 @@
/*
* Copyright (C)2014-2020 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package js.node.stream;
import haxe.extern.EitherType;
import js.node.Stream;
import js.node.events.EventEmitter.Event;
import js.node.stream.Readable.IReadable;
#if haxe4
import js.lib.Error;
import js.lib.Object;
import js.lib.Uint8Array;
#else
import js.Error;
import js.html.Uint8Array;
#end
/**
Writable streams are an abstraction for a destination to which data is written.
@see https://nodejs.org/api/stream.html#stream_writable_streams
**/
@:enum abstract WritableEvent<T:haxe.Constraints.Function>(Event<T>) to Event<T> {
/**
The `'close'` event is emitted when the stream and any of its underlying resources
(a file descriptor, for example) have been closed.
The event indicates that no more events will be emitted, and no further computation will occur.
@see https://nodejs.org/api/stream.html#stream_event_close
**/
var Close:WritableEvent<Void->Void> = "close";
/**
If a call to stream.write(chunk) returns `false`, the `'drain'` event will be emitted
when it is appropriate to resume writing data to the stream.
@see https://nodejs.org/api/stream.html#stream_event_drain
**/
var Drain:WritableEvent<Void->Void> = "drain";
/**
The `'error'` event is emitted if an `error` occurred while writing or piping data.
The listener callback is passed a single Error argument when called.
@see https://nodejs.org/api/stream.html#stream_event_error
**/
var Error:WritableEvent<Error->Void> = "error";
/**
The `'finish'` event is emitted after the stream.end() method has been called,
and all data has been flushed to the underlying system.
@see https://nodejs.org/api/stream.html#stream_event_finish
**/
var Finish:WritableEvent<Void->Void> = "finish";
/**
The `'pipe'` event is emitted when the stream.pipe() method is called on a readable stream,
adding this writable to its set of destinations.
@see https://nodejs.org/api/stream.html#stream_event_pipe
**/
var Pipe:WritableEvent<IReadable->Void> = "pipe";
/**
The `'unpipe'` event is emitted when the stream.unpipe() method is called on a Readable stream,
removing this Writable from its set of destinations.
@see https://nodejs.org/api/stream.html#stream_event_unpipe
**/
var Unpipe:WritableEvent<IReadable->Void> = "unpipe";
}
/**
The Writable stream interface is an abstraction for a destination that you are writing data to.
Examples of writable streams include:
- http requests, on the client
- http responses, on the server
- fs write streams
- zlib streams
- crypto streams
- tcp sockets
- child process stdin
- process.stdout, process.stderr
**/
@:jsRequire("stream", "Writable")
extern class Writable<TSelf:Writable<TSelf>> extends Stream<TSelf> implements IWritable {
/**
The `writable.cork()` method forces all written data to be buffered in memory.
The buffered data will be flushed when either the `stream.uncork()` or `stream.end()` methods are called.
@see https://nodejs.org/api/stream.html#stream_writable_cork
**/
function cork():Void;
/**
Destroy the stream. Optionally emit an `'error'` event, and emit a `'close'` event unless `emitClose` is set in `false`.
After this call, the writable stream has ended and subsequent calls to `write()` or `end()` will result in an `ERR_STREAM_DESTROYED` error.
This is a destructive and immediate way to destroy a stream. Previous calls to `write()` may not have drained, and may trigger an `ERR_STREAM_DESTROYED` error.
Use `end()` instead of destroy if data should flush before close, or wait for the `'drain'` event before destroying the stream.
Implementors should not override this method, but instead implement `writable._destroy()`.
@see https://nodejs.org/api/stream.html#stream_writable_destroy_error
**/
function destroy(?error:Error):TSelf;
/**
Is `true` after `writable.destroy()` has been called.
@see https://nodejs.org/api/stream.html#stream_writable_destroyed
**/
var destroyed(default, null):Bool;
/**
Calling the `writable.end()` method signals that no more data will be written to the Writable.
The optional `chunk` and `encoding` arguments allow one final additional chunk of data to be written immediately before closing the stream.
If provided, the optional `callback` function is attached as a listener for the 'finish' event.
@see https://nodejs.org/api/stream.html#stream_writable_end_chunk_encoding_callback
**/
@:overload(function(?callback:EitherType<Void->Void, Null<Error>->Void>):Void {})
function end(chunk:Dynamic, ?encoding:String, ?callback:EitherType<Void->Void, Null<Error>->Void>):Void;
/**
The `writable.setDefaultEncoding()` method sets the default `encoding` for a Writable stream.
@see https://nodejs.org/api/stream.html#stream_writable_setdefaultencoding_encoding
**/
function setDefaultEncoding(encoding:String):TSelf;
/**
The `writable.uncork()` method flushes all data buffered since `stream.cork()` was called.
@see https://nodejs.org/api/stream.html#stream_writable_uncork
**/
function uncork():Void;
/**
Is `true` if it is safe to call `writable.write()`.
@see https://nodejs.org/api/stream.html#stream_writable_writable
**/
var writable(default, null):Bool;
/**
Is `true` after `writable.end()` has been called. This property
does not indicate whether the data has been flushed, for this use
`writable.writableFinished` instead.
@see https://nodejs.org/api/stream.html#stream_writable_writableended
**/
var writableEnded(default, null):Bool;
/**
Is set to `true` immediately before the 'finish' event is emitted.
@see https://nodejs.org/api/stream.html#stream_writable_writablefinished
**/
var writableFinished(default, null):Bool;
/**
Return the value of `highWaterMark` passed when constructing this `Writable`.
@see https://nodejs.org/api/stream.html#stream_writable_writablehighwatermark
**/
var writablehighWaterMark(default, null):Int;
/**
This property contains the number of bytes (or objects) in the queue ready to be written.
The value provides introspection data regarding the status of the `highWaterMark`.
@see https://nodejs.org/api/stream.html#stream_writable_writablelength
**/
var writableLength(default, null):Int;
/**
Getter for the property `objectMode` of a given `Writable` stream.
@see https://nodejs.org/api/stream.html#stream_writable_writableobjectmode
**/
var writableObjectMode(default, null):Bool;
/**
The `writable.write()` method writes some data to the stream, and calls the supplied `callback` once the data has been fully handled.
If an error occurs, the `callback` may or may not be called with the error as its first argument.
To reliably detect write errors, add a listener for the `'error'` event.
@see https://nodejs.org/api/stream.html#stream_writable_write_chunk_encoding_callback
**/
function write(chunk:Dynamic, ?encoding:String, ?callback:EitherType<Void->Void, Null<Error>->Void>):Bool;
// --------- API for implementing a Writable Stream -----------------------
/**
@see https://nodejs.org/api/stream.html#stream_constructor_new_stream_writable_options
**/
function new(?options:WritableNewOptionsAdapter);
/**
All `Writable` stream implementations must provide a `writable._write()` method to send data to the underlying resource.
@see https://nodejs.org/api/stream.html#stream_writable_write_chunk_encoding_callback_1
**/
private function _write(chunk:Dynamic, encoding:String, callback:Null<Error>->Void):Void;
/**
This function **MUST NOT** be called by application code directly.
It should be implemented by child classes, and called by the internal `Writable` class methods only.
@see https://nodejs.org/api/stream.html#stream_writable_writev_chunks_callback
**/
private function _writev(chunks:Array<Chunk>, callback:Null<Error>->Void):Void;
/**
The `_destroy()` method is called by `writable.destroy()`.
It can be overridden by child classes but it **must not** be called directly.
@see https://nodejs.org/api/stream.html#stream_writable_destroy_err_callback
**/
private function _destroy(err:Null<Error>, callback:Null<Error>->Void):Void;
/**
The `_final()` method **must not** be called directly.
t may be implemented by child classes, and if so, will be called by the internal `Writable` class methods only.
@see https://nodejs.org/api/stream.html#stream_writable_final_callback
**/
private function _final(callback:Null<Error>->Void):Void;
// --------- TTY module API ----------------------------------------------
/**
Terminal write streams (i.e. process.stdout) have this property set to true.
It is false for any other write streams.
@see https://nodejs.org/api/tty.html#tty_writestream_istty
**/
var isTTY(default, null):Bool;
}
/**
@see https://nodejs.org/api/stream.html#stream_constructor_new_stream_writable_options
**/
typedef WritableNewOptions = {
/**
`highWaterMark` <number> Buffer level when stream.write() starts returning `false`. Default: `16384` (16kb), or 16 for `objectMode` streams.
**/
@:optional var highWaterMark:Int;
/**
`decodeStrings` <boolean> Whether to encode `string`s passed to stream.write() to `Buffer`s (with the encoding specified in the stream.write() call) before passing them to stream._write().
Other types of data are not converted (i.e. `Buffer`s are not decoded into `string`s). Setting to false will prevent strings from being converted.
Default: `true`.
**/
@:optional var decodeStrings:Bool;
/**
`defaultEncoding` <string> The default encoding that is used when no encoding is specified as an argument to stream.write().
Default: `'utf8'`.
**/
@:optional var defaultEncoding:String;
/**
`objectMode` <boolean> Whether or not the stream.write(anyObj) is a valid operation. When set,
it becomes possible to write JavaScript values other than string, `Buffer` or `Uint8Array` if supported by the stream implementation.
Default: `false`.
**/
@:optional var objectMode:Bool;
/**
`emitClose` <boolean> Whether or not the stream should emit `'close'` after it has been destroyed.
Default: `true`.
**/
@:optional var emitClose:Bool;
/**
`write` <Function> Implementation for the stream._write() method.
**/
#if haxe4
@:optional var write:(chunk:Dynamic, encoding:String, callback:Null<Error>->Void) -> Void;
#else
@:optional var write:Dynamic->String->Null<Error>->Void->Void;
#end
/**
`writev` <Function> Implementation for the stream._writev() method.
**/
#if haxe4
@:optional var writev:(chunks:Array<Chunk>, callback:Null<Error>->Void) -> Void;
#else
@:optional var writev:Array<Chunk>->(Null<Error>->Void)->Void;
#end
/**
`destroy` <Function> Implementation for the stream._destroy() method.
**/
#if haxe4
@:optional var destroy:(error:Null<Error>, callback:Null<Error>->Void) -> Void;
#else
@:optional var destroy:Null<Error>->(Null<Error>->Void)->Void;
#end
/**
`final` <Function> Implementation for the stream._final() method.
**/
// TODO @native in typedef cannot work now
// @:native("final")
#if haxe4
@:optional var final_:(error:Null<Error>) -> Void;
#else
@:optional var final_:Null<Error>->Void;
#end
/**
`autoDestroy` <boolean> Whether this stream should automatically call .destroy() on itself after ending. Default: false.
**/
@:optional var autoDestroy:Bool;
}
@:forward
abstract WritableNewOptionsAdapter(WritableNewOptions) {
@:from
public static function from(options:WritableNewOptions):WritableNewOptionsAdapter {
if (!Reflect.hasField(options, "final")) {
#if haxe4
Object.defineProperty(options, "final", {get: function() return options.final_});
#else
untyped __js__("Object.defineProperty({0}, {1}, {2})", options, "final", {get: function() return options.final_});
#end
}
return cast options;
}
}
/**
Writable interface used for type parameter constraints.
See `Writable` for actual class documentation.
**/
@:remove
extern interface IWritable extends IStream {
function cork():Void;
function destroy(?error:Error):IWritable;
var destroyed(default, null):Bool;
@:overload(function(?callback:EitherType<Void->Void, Null<Error>->Void>):Void {})
function end(chunk:Dynamic, ?encoding:String, ?callback:EitherType<Void->Void, Null<Error>->Void>):Void;
function setDefaultEncoding(encoding:String):IWritable;
function uncork():Void;
var writable(default, null):Bool;
var writableEnded(default, null):Bool;
var writableFinished(default, null):Bool;
var writablehighWaterMark(default, null):Int;
var writableLength(default, null):Int;
var writableObjectMode(default, null):Bool;
function write(chunk:Dynamic, ?encoding:String, ?callback:EitherType<Void->Void, Null<Error>->Void>):Bool;
var isTTY(default, null):Bool;
}
typedef Chunk = {
var chunk:Dynamic;
var encoding:String;
}