Object built-in object

Object RangeStream

Range query stream to read objects

The RangeStream object is used to SeekableStreamThe object data is intercepted. Creation method:

1 2 3 4 5
var stm = new io.RangeStream(stream, '0-10'); stm.end // 11 var stm = new io.RangeStream(stream, 0, 10); stm.end // 10

Inheritance

#lineWidth: 1.5 #font: Helvetica,sans-Serif #fontSize: 10 #leading: 1.6 #.this: fill=lightgray #.class: fill=white [<class>object|toString();toJSON()] [<class>Stream|fd|read();write();flush();close();copyTo()] [<class>SeekableStream|seek();tell();rewind();size();readAll();truncate();eof();stat()] [<this>RangeStream|new RangeStream()|begin;end] [object] <:- [Stream] [Stream] <:- [SeekableStream] [SeekableStream] <:- [RangeStream] Stream fd read() write() flush() close() copyTo() RangeStream new RangeStream() begin end object toString() toJSON() SeekableStream seek() tell() rewind() size() readAll() truncate() eof() stat()

Constructor

RangeStream

RangeStream constructor

1 2
new RangeStream(SeekableStream stm, String range);

Call parameters:

  • stm: SeekableStream, The binary base stream object of RangeStream, must be SeekableStream
  • range: String, a string describing the range, the format is'begin-[end]','[begin]-end'

RangeStream constructor

1 2 3
new RangeStream(SeekableStream stm, Long begin, Long end);

Call parameters:

  • stm: SeekableStream, The binary base stream object of RangeStream, must be SeekableStream
  • begin: Long, the starting position of reading content from stm
  • end: Long, the end position of reading content from stm

Member attributes

begin

Long, query range start value

1
readonly Long RangeStream.begin;

end

Long, query the end value of the range

1
readonly Long RangeStream.end;

fd

Integer, query Stream The corresponding file descriptor value, implemented by the subclass

1
readonly Integer RangeStream.fd;

Member function

seek

Move the current operating position of the file

1 2
RangeStream.seek(Long offset, Integer whence = fs.SEEK_SET);

Call parameters:

  • offset: Long, specify a new location
  • whence: Integer, specify the position reference, the allowed values ​​are: SEEK_SET, SEEK_CUR, SEEK_END

tell

Query the current position of the stream

1
Long RangeStream.tell();

Return result:

  • Long, Returns the current position of the stream

rewind

Move the current position to the beginning of the stream

1
RangeStream.rewind();

size

Query stream size

1
Long RangeStream.size();

Return result:

  • Long, Return stream size

readAll

Read all remaining data from the stream

1
Buffer RangeStream.readAll() async;

Return result:

  • Buffer, Return the data read from the stream, if there is no data to read, or the connection is interrupted, then return null

truncate

Modify the file size, if the new size is smaller than the original size, the file is truncated

1
RangeStream.truncate(Long bytes) async;

Call parameters:

  • bytes: Long, new file size

eof

Check if the file is to the end

1
Boolean RangeStream.eof();

Return result:

  • Boolean, Return True to indicate the end

stat

Query the basic information of the current file

1
Stat RangeStream.stat() async;

Return result:

  • Stat, return Stat Object description file information

read

Read data of the specified size from the stream

1
Buffer RangeStream.read(Integer bytes = -1) async;

Call parameters:

  • bytes: Integer, specify the amount of data to be read, the default is to read a random size data block, the size of the data read depends on the device

Return result:

  • Buffer, Return the data read from the stream, if there is no data to read, or the connection is interrupted, then return null

write

Write the given data to the stream

1
RangeStream.write(Buffer data) async;

Call parameters:

  • data: Buffer, Given the data to be written

flush

Write the contents of the file buffer to the physical device

1
RangeStream.flush() async;

close

Close the current stream object

1
RangeStream.close() async;

copyTo

Copy the stream data to the target stream

1 2
Long RangeStream.copyTo(Stream stm, Long bytes = -1) async;

Call parameters:

  • stm: Stream, The target stream object
  • bytes: Long, the number of bytes copied

Return result:

  • Long, Returns the number of bytes copied

toString

Returns the string representation of the object, generally returns "[Native Object]", the object can be re-implemented according to its own characteristics

1
String RangeStream.toString();

Return result:

  • String, Returns the string representation of the object

toJSON

Returns the JSON format representation of the object, generally returns a collection of readable attributes defined by the object

1
Value RangeStream.toJSON(String key = "");

Call parameters:

  • key: String, unused

Return result:

  • Value, Returns a value containing JSON serializable