Changes

Jump to: navigation, search

ServerJS/Encodings

1,420 bytes removed, 23:50, 9 April 2009
API: move write/read API into separate page
=== Class: Converter ===
There also should be a class enc.Converter for more advanced conversion. Please note that the interface is ''one way''. Despite the fact that it has two methods, it's ''one way''. It only supports ''encoding'', '''no''' decoding! Multiple people have got that wrong when glancing over it, so it's emphasised here. ; [Constructor] Converter(from, totranscoding): Where from and to are the encoding names.; [Method] write(byteStringOrArray): Convert input from a ByteString or ByteArray. The results are stored in an internal buffer, and also those parts of byteStringOrArray that could not be converted (for multi-byte encodings, in a separate buffer).: Returns nothing.; [Method] read([byteArray,] [maximumSize]): Read maximumSize bytes or as many bytes as available out of the internal buffer. If byteArray is specified, the data is ''appended'' to that ByteArray.: Returns a ByteString if byteArray is not specified, or byteArray itself otherwise.; [Method] close(): Close the stream. Throws an exception if there was a conversion error (specifically, a partial multibyte character).: Returns nothing and takes no parameters. '''TODO''': Which exception to throw on error? Example usage:  Converter = require('encodings').Converter converter = new Converter('iso-8859-1', 'utf-32') converter.write(input) // input is a ByteString output = converter.read() // output is a ByteString converter.close() === Alternative: Converter === There is another way the Converter interface could work. It should be more efficient (less memory consumption, less CPU usage) than the other Converter interface.
; [Constructor] Converter(from, to)
: Close the stream. Throws an exception if there was a conversion error (specifically, a partial multibyte character).
: Returns nothing and takes no parameters.
 
'''TODO''': Which exception to throw on error?
Example:
converter.close()
// output is the complete conversion of all the input chunks concatenated now
 
(See [[ServerJS/Encodings/OldClass]] for another API.)
62
edits

Navigation menu