serializer.text stream - Palamecia/mint GitHub Wiki

Module serializer.text-stream

Description

load serializer.text-stream

This module provides the Serializer.TextStream class which implement a stream interface for reading and writing text on any kind of object.

Packages

Classes

Serializer.TextStream

This class provides an interface to use any object as a stream for reading and writing text.

Public members

Modifiers Member Description
const << Writes the string data to the stream, and returns a reference to the stream. ...
const >> Reads a word from the stream and stores it in data, then returns a reference ...
const getCodec Returns the codec that is current assigned to the stream. If the stream use t...
const isEmpty Returns true if the stream has no more data to read; otherwise returns false. ...
const new Creates a new stream on the stream object. If the stream object provides both ``...
const read Reads all remaining data from the stream, and returns it as a string or returns ``...
const readChar Reads the next character from the stream, and returns it as a string or returns ``...
const readLine Reads the next line from the stream, and returns it as a string or returns none...
const readLines Returns an iterator on each remaining lines of the stream.
const readUntil Reads data from the stream until delim is found and returns it as a string or...
const readWord Reads a word from the stream, and returns it as a string or returns none if n...
const setCodec Sets the codec for this stream to codec. The codec is used for decoding any d...
const write Writes the content of data to the stream. The write method of the underlying ...

Private members

Modifiers Member Description
final byteBuffer Internal read byte buffer.
final bytePos Internal read byte buffer offset.
final charBuffer Internal read char buffer.
final charPos Internal read char buffer offset.
final codec Internal text codec.
final const decode Refill the internal read char buffer with some data from the codec. Returns true...
final isSourceExhausted
final const refill Refill the internal read byte buffer with some data from the stream. Returns ``...
final stream Internal underlying stream.

Descriptions

Serializer.TextStream.<<

def (self, data)

Writes the string data to the stream, and returns a reference to the stream. The string is first encoded using the assigned codec (the default is UTF-8) before it is written to the stream.

Serializer.TextStream.>>

def (self, data)

Reads a word from the stream and stores it in data, then returns a reference to the stream. Words are separated by whitespace (i.e., all characters for which isSpace returns true).

Leading whitespace are skipped.

Serializer.TextStream.byteBuffer

null

Internal read byte buffer.

Serializer.TextStream.bytePos

0

Internal read byte buffer offset.

Serializer.TextStream.charBuffer

''

Internal read char buffer.

Serializer.TextStream.charPos

0

Internal read char buffer offset.

Serializer.TextStream.codec

null

Internal text codec.

Serializer.TextStream.decode

def (self)

Refill the internal read char buffer with some data from the codec. Returns true if decoded data were added to the read buffer; otherwise returns false.

Serializer.TextStream.getCodec

def (const self)

Returns the codec that is current assigned to the stream. If the stream use the default codec (UTF-8), null is returned.

Serializer.TextStream.isEmpty

def (const self)

Returns true if the stream has no more data to read; otherwise returns false.

The underlying stream may be checked with one of those methods in the following order: isEmpty, isOver or atEnd. If none of these methods are defined, false is returned.

Serializer.TextStream.isSourceExhausted

def (self)

Serializer.TextStream.new

def (self, stream, codec = Codec.TextCodec ())

Creates a new stream on the stream object.

If the stream object provides both readSome, read and write methods, the object is used as is; otherwise an instance of Serializer.BufferedStream is created to provide these methods.

The codec parameter is used to specify the text codec to use for reading and writing text.

If stream is not a valid object, none is returned.

Serializer.TextStream.read

def (self)

Reads all remaining data from the stream, and returns it as a string or returns none if no more character is available on the stream.

Serializer.TextStream.readChar

def (self)

Reads the next character from the stream, and returns it as a string or returns none if no more character is available on the stream. Data is read until a valid character is decoded or if the end of stream is detected.

Serializer.TextStream.readLine

def (self)

Reads the next line from the stream, and returns it as a string or returns none if no more character is available on the stream. Data is read until a '\n' character is read or if the end of stream is detected.

Serializer.TextStream.readLines

def (self)

Returns an iterator on each remaining lines of the stream.

Serializer.TextStream.readUntil

def (self, delim)

Reads data from the stream until delim is found and returns it as a string or returns none if no more character is available on the stream. The delimiter is consumed but is not included in the returned string. Data is read until the delimiter is read or if the end of stream is detected.

Serializer.TextStream.readWord

def (self)

Reads a word from the stream, and returns it as a string or returns none if no more character is available on the stream. Words are separated by whitespace (i.e., all characters for which isSpace returns true). Leading whitespace are skipped.

Serializer.TextStream.refill

def (self)

Refill the internal read byte buffer with some data from the stream. Returns true if raw data were added to the read buffer; otherwise returns false.

Serializer.TextStream.setCodec

def (self, codec)

Sets the codec for this stream to codec. The codec is used for decoding any data that is read from the file, and for encoding any data that is written.

Serializer.TextStream.stream

null

Internal underlying stream.

Serializer.TextStream.write

def (self, data)

Writes the content of data to the stream.

The write method of the underlying object is used to write the data.