ServerJS/Encodings: Difference between revisions

Jump to navigation Jump to search
→‎Class: Transcoder: change Transcoder API in a _major_ way.
m (updated discussion links)
(→‎Class: Transcoder: change Transcoder API in a _major_ way.)
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 (as a ByteString) as much output as could be converted.
: If outputByteArray was passed, returns outputByteArray, otherwise returns <u>nothing and the output is accumulated in an internal buffer.</u>
; [Method] close()
; [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).
: Returns nothing and takes no parameters.
: <u>Writes the remaining output bytes (including those that were accumulated because push was called without an outputByteArray) 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 56:
   Transcoder = require('encodings').Transcoder
   Transcoder = require('encodings').Transcoder
   transcoder = new Transcoder('iso-8859-1', 'utf-32')
   transcoder = new Transcoder('iso-8859-1', 'utf-32')
   output = transcoder.push(input) // input is a ByteString, and output too
   transcoder.push(input) // input is a ByteString
   transcoder.close()
   output = transcoder.close() // and output is a ByteString too


Another example:
Another example:
Line 66: Line 66:
           transcoder.push(input, output)
           transcoder.push(input, output)
   }
   }
   transcoder.close()
   transcoder.close(output)
   // output is the complete conversion of all the input chunks concatenated now
   // output is the complete conversion of all the input chunks concatenated now


62

edits

Navigation menu