62
edits
(→Class: Transcoder: change Transcoder API in a _major_ way.) |
(→Class: Transcoder: split push into push and pushAccumulate) |
||
| Line 45: | Line 45: | ||
; [Method] push(byteStringOrArray[, outputByteArray]) | ; [Method] push(byteStringOrArray[, outputByteArray]) | ||
: Convert input from a ByteString or ByteArray. Those parts of byteStringOrArray that could not be converted (for multi-byte encodings) are stored in a buffer. If outputByteArray is passed, the results are ''appended'' to outputByteArray. | : Convert input from a ByteString or ByteArray. Those parts of byteStringOrArray that could not be converted (for multi-byte encodings) are stored in a buffer. If outputByteArray is passed, the results are ''appended'' to outputByteArray. | ||
: If outputByteArray was passed, returns outputByteArray, otherwise returns <u> | : If outputByteArray was passed, returns outputByteArray, otherwise returns <u>the converted bytes as a ByteString</u>. | ||
: <u>The result will also contain bytes accumulated in prior calls to pushAccumulate.</u> | |||
; <u>[Method] pushAccumulate(byteStringOrArray)</u> | |||
: <u>Convert input from a ByteString or ByteArray into an internal buffer that will be read out the next time push or close is called.</u> | |||
; [Method] close([outputByteArray]) | ; [Method] close([outputByteArray]) | ||
: Close the stream. Throws an exception if there was a conversion error (specifically, a partial multibyte character). | : Close the stream. Throws an exception if there was a conversion error (specifically, a partial multibyte character). | ||
: <u>Writes the remaining output bytes (including those that were accumulated | : <u>Writes the remaining output bytes (including those that were accumulated in pushAccumulate) into the here given outputByteArray (appended) or a new ByteString. If outputByteArray is given, it is returned, otherwise the ByteString is returned.</u> | ||
'''TODO''': Which exception to throw on error? | '''TODO''': Which exception to throw on error? | ||
| Line 56: | Line 59: | ||
Transcoder = require('encodings').Transcoder | Transcoder = require('encodings').Transcoder | ||
transcoder = new Transcoder('iso-8859-1', 'utf-32') | transcoder = new Transcoder('iso-8859-1', 'utf-32') | ||
transcoder. | transcoder.pushAccumulate(input) // input is a ByteString | ||
output = transcoder.close() // and output is a ByteString too | output = transcoder.close() // and output is a ByteString too | ||
edits