ServerJS/IO/A: Difference between revisions

From MozillaWiki
< ServerJS‎ | IO
Jump to navigation Jump to search
(Created page with '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 a…')
 
No edit summary
Line 26: Line 26:
:  
:  


;readInto(buffer *Array, [begin Number], [end Number]) Number  
;readInto(buffer ByteArray, [begin Number], [end Number]) Number  
:
:


Line 32: Line 32:
:  
:  


;write(b Binary) Number
;write(b Binary, [begin Number], [end Number]) Number
:
:



Revision as of 09:46, 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.

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 implementing the reading and writing of 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

Buffered I/O

Text I/O