ServerJS/IO/A: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
mNo edit summary |
||
Line 2: | Line 2: | ||
This document describes an interface for reading and writing stream of raw bytes, and classes built on top of it to provide buffered and 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 buffered and string based reading and writing. | ||
This specification refers to the ByteString and ByteArray classes defined in the [[ServerJS/Binary/B|Binary/B]] proposal, but it should be easy to adapt it to any definition of binary buffers or arrays. | |||
== Specification == | == Specification == | ||
Line 16: | Line 18: | ||
:Whether the Stream class provides a public constructor, and what the arguments of the constructor are, is not part of this specification. The process of creating actual Stream objects is implementation specific. | :Whether the Stream class provides a public constructor, and what the arguments of the constructor are, is not part of this specification. The process of creating actual Stream objects is implementation specific. | ||
:Various built-in modules such as the file module will know how to build native Stream objects in a platform specific way. Application classes should be able to extend the Stream class through JavaScript prototype chaining. However, duck typing should also work for Stream objects, meaning that any object implementing the Stream interface should work for code expecting an io.Stream object. | :Various built-in modules such as the [[ServerJS/Filesystem_API|file module]] will know how to build native Stream objects in a platform specific way. Application classes should be able to extend the Stream class through JavaScript prototype chaining. However, duck typing should also work for Stream objects, meaning that any object implementing the Stream interface ''should'' work for code expecting an io.Stream object. | ||
===== Instance Methods ===== | ===== Instance Methods ===== |
Revision as of 09:54, 7 September 2009
Work in progress.
This document describes an interface for reading and writing stream of raw bytes, and classes built on top of it to provide buffered and string based reading and writing.
This specification refers to the ByteString and ByteArray classes defined in the Binary/B proposal, but it should be easy to adapt it to any definition of binary buffers or arrays.
Specification
Platforms implementing this specification must provide a top level io module. The io module defines an interface for raw, byte based I/O, and classes for buffered and text based I/O layered upon the raw I/O.
Raw I/O
Stream
The Stream class implements a stream for reading and writing raw bytes.
- Constructor
- Whether the Stream class provides a public constructor, and what the arguments of the constructor are, is not part of this specification. The process of creating actual Stream objects is implementation specific.
- Various built-in modules such as the file module will know how to build native Stream objects in a platform specific way. Application classes should be able to extend the Stream class through JavaScript prototype chaining. However, duck typing should also work for Stream objects, meaning that any object implementing the Stream interface should work for code expecting an io.Stream object.
Instance Methods
- read(n Number) ByteString
- readAll() ByteString
- readInto(buffer ByteArray, [begin Number], [end Number]) Number
- skip(n Number) Number
- write(b Binary, [begin Number], [end Number]) Number
- tell() Number
- seek(position Number, whence Number)
- truncate([length Number=0])
- rewind()
- readable() Boolean
- writable() Boolean
- seekable() Boolean