55
edits
No edit summary |
|||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
''First draft.'' | |||
This document describes an interface for reading and writing stream of raw bytes, and classes built on top of it to provide string based reading and writing. | This document describes an interface for reading and writing stream of raw bytes, and classes built on top of it to provide string based reading and writing. | ||
| Line 34: | Line 34: | ||
;read(n Number) ByteString | ;read(n Number) ByteString | ||
:Read up to n bytes from the stream, or until the end of the stream has been reached. | :Read up to n bytes from the stream, or until the end of the stream has been reached. An empty ByteString is returned when the end of the stream has been reached. | ||
;readAll() ByteString | ;readAll() ByteString | ||
:Read all the bytes from the stream until its end has been reached. | :Read all the bytes from the stream until its end has been reached. An empty ByteString is returned when the end of the stream has been reached. | ||
;readInto(buffer ByteArray, [begin Number], [end Number]) Number | ;readInto(buffer ByteArray, [begin Number], [end Number]) Number | ||
:Read bytes from the stream into the ByteArray buffer. | :Read bytes from the stream into the ByteArray buffer. This method does not increase the length of the ByteArray buffer. Returns the number of bytes read, or -1 if the end of the stream has been reached. '''''Note''': Can we safely return 0 on EOF?'' | ||
;skip(n Number) Number | ;skip(n Number) Number | ||
: | :Try to skip over n bytes in the stream. | ||
;write(b Binary, [begin Number], [end Number]) Number | ;write(b Binary, [begin Number], [end Number]) Number | ||
:Write bytes from b to the stream. If begin and end are specified, only the range starting at begin and ending before end are written. | :Write bytes from b to the stream. If begin and end are specified, only the range starting at begin and ending before end are written. Returns the number of bytes actually written. | ||
;readable() Boolean | ;readable() Boolean | ||
edits