62
edits
(→API: fix example, add alternative API proposal) |
|||
| Line 65: | Line 65: | ||
Converter = require('encodings').Converter | Converter = require('encodings').Converter | ||
converter = new Converter('iso-8859-1', 'utf-32') | converter = new Converter('iso-8859-1', 'utf-32') | ||
converter. | converter.write(input) // input is a ByteString | ||
output = converter. | output = converter.read() // output is a ByteString | ||
converter.close() | |||
=== Alternative: Converter === | |||
There is another way the Converter interface could work. | |||
; [Constructor] Converter(from, to) | |||
: Where from and to are the encoding names. | |||
; [Method] push(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 (as a ByteString) as much as could be converted. | |||
; [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. | |||
Example: | |||
Converter = require('encodings').Converter | |||
converter = new Converter('iso-8859-1', 'utf-32') | |||
output = converter.push(input) // input is a ByteString, and output too | |||
converter.close() | |||
edits