62
edits
(→API: move write/read API into separate page) |
(→Class: Converter: => Transcoder) |
||
| Line 41: | Line 41: | ||
: encodingCheckerFunction takes the encoding name as a parameter and returns true-ish if the encoding should be listed. Regexes should also be supported. If the parameter is missing, returns all supported encodings. | : encodingCheckerFunction takes the encoding name as a parameter and returns true-ish if the encoding should be listed. Regexes should also be supported. If the parameter is missing, returns all supported encodings. | ||
=== Class: | === Class: Transcoder === | ||
There also should be a class enc. | There also should be a class enc.Transcoder for general transcoding conversion (between ByteStrings or ByteArrays). | ||
; [Constructor] | ; [Constructor] Transcoder(from, to) | ||
: Where from and to are the encoding names. | : Where from and to are the encoding names. | ||
; [Method] push(byteStringOrArray[, outputByteArray]) | ; [Method] push(byteStringOrArray[, outputByteArray]) | ||
| Line 58: | Line 58: | ||
Example: | Example: | ||
Transcoder = require('encodings').Transcoder | |||
transcoder = new Transcoder('iso-8859-1', 'utf-32') | |||
output = | output = transcoder.push(input) // input is a ByteString, and output too | ||
transcoder.close() | |||
Another example: | Another example: | ||
transcoder = new Transcoder('utf-32', 'utf-8') | |||
output = new ByteArray() | output = new ByteArray() | ||
while (input = readSomeByteFromSomewhere()) { | while (input = readSomeByteFromSomewhere()) { | ||
transcoder.push(input, output) | |||
} | } | ||
transcoder.close() | |||
// output is the complete conversion of all the input chunks concatenated now | // output is the complete conversion of all the input chunks concatenated now | ||
(See [[ServerJS/Encodings/OldClass]] for another API.) | (See [[ServerJS/Encodings/OldClass]] for another API.) | ||
edits