streams
nimony/lib/std/streams.nim
type Stream = ref StreamObjAll procedures of this module use this type. Procedures don't directly use StreamObj.
type StreamObj = object closeImpl: proc (s: ref StreamObj) {.nimcall, raises: ErrorCode, tags: [WriteIOEffect].} atEndImpl: proc (s: ref StreamObj): bool {.nimcall, raises: ErrorCode, tags: [].} setPositionImpl: proc (s: ref StreamObj, pos: int64) {.nimcall, raises: ErrorCode, tags: [].} getPositionImpl: proc (s: ref StreamObj): int64 {.nimcall, raises: ErrorCode, tags: [].} readDataStrImpl: proc (s: ref StreamObj, buffer: var string, slice: HSlice): int64 {.nimcall, raises: ErrorCode, tags: [ReadIOEffect].} readLineImpl: proc (s: ref StreamObj, line: var string): bool {.nimcall, raises: ErrorCode, tags: [ReadIOEffect].} readDataImpl: proc (s: ref StreamObj, buffer: pointer, bufLen: int64): int64 {.nimcall, raises: ErrorCode, tags: [ReadIOEffect].} peekDataImpl: proc (s: ref StreamObj, buffer: pointer, bufLen: int64): int64 {.nimcall, raises: ErrorCode, tags: [ReadIOEffect].} writeDataImpl: proc (s: ref StreamObj, buffer: pointer, bufLen: int64) {.nimcall, raises: ErrorCode, tags: [WriteIOEffect].} flushImpl: proc (s: ref StreamObj) {.nimcall, raises: ErrorCode, tags: [WriteIOEffect].}
proc flush(s: ref StreamObj)Flushes the buffers that the stream
smight use.proc close(s: ref StreamObj)Closes the stream
s.proc atEnd(s: ref StreamObj): boolChecks if more data can be read from
s. Returnstrueif all data has been read.proc setPosition(s: ref StreamObj; pos: int64)Sets the position
posof the streams.proc getPosition(s: ref StreamObj): int64Retrieves the current position in the stream
s.proc readData(s: ref StreamObj; buffer: pointer; bufLen: int64): int64Low level proc that reads data into an untyped
bufferofbufLensize.proc readDataStr(s: ref StreamObj; buffer: var string; slice: HSlice): int64Low level proc that reads data into a string
bufferatslice.proc readAll(s: ref StreamObj): stringReads all available data.
proc peekData(s: ref StreamObj; buffer: pointer; bufLen: int64): int64Low level proc that reads data into an untyped
bufferofbufLensize without moving stream position.proc writeData(s: ref StreamObj; buffer: pointer; bufLen: int64)Low level proc that writes an untyped
bufferofbufLensize to the streams.proc write(s: ref StreamObj; x: T)Generic write procedure. Writes
xto the streams.proc write(s: ref StreamObj; x: string)Writes the string
xto the streams. No length field or terminating zero is written.proc writeLine(s: ref StreamObj; x: string)Writes a string followed by a newline to the stream
s.proc read(s: ref StreamObj; result: var T)Generic read procedure. Reads
resultfrom the streams.proc peek(s: ref StreamObj; result: var T)Generic peek procedure. Peeks
resultfrom the streams.proc readChar(s: ref StreamObj): charReads a char from the stream
s. Returns '\0' as an EOF marker.proc peekChar(s: ref StreamObj): charPeeks a char from the stream
s. Returns '\0' as an EOF marker.proc readBool(s: ref StreamObj): boolReads a bool from the stream
s.proc peekBool(s: ref StreamObj): boolPeeks a bool from the stream
s.proc readInt8(s: ref StreamObj): int8Reads an int8 from the stream
s.proc peekInt8(s: ref StreamObj): int8Peeks an int8 from the stream
s.proc readInt16(s: ref StreamObj): int16Reads an int16 from the stream
s.proc peekInt16(s: ref StreamObj): int16Peeks an int16 from the stream
s.proc readInt32(s: ref StreamObj): int32Reads an int32 from the stream
s.proc peekInt32(s: ref StreamObj): int32Peeks an int32 from the stream
s.proc readInt64(s: ref StreamObj): int64Reads an int64 from the stream
s.proc peekInt64(s: ref StreamObj): int64Peeks an int64 from the stream
s.proc readUint8(s: ref StreamObj): uint8Reads a uint8 from the stream
s.proc peekUint8(s: ref StreamObj): uint8Peeks a uint8 from the stream
s.proc readUint16(s: ref StreamObj): uint16Reads a uint16 from the stream
s.proc peekUint16(s: ref StreamObj): uint16Peeks a uint16 from the stream
s.proc readUint32(s: ref StreamObj): uint32Reads a uint32 from the stream
s.proc peekUint32(s: ref StreamObj): uint32Peeks a uint32 from the stream
s.proc readUint64(s: ref StreamObj): uint64Reads a uint64 from the stream
s.proc peekUint64(s: ref StreamObj): uint64Peeks a uint64 from the stream
s.proc readFloat32(s: ref StreamObj): float32Reads a float32 from the stream
s.proc peekFloat32(s: ref StreamObj): float32Peeks a float32 from the stream
s.proc readFloat64(s: ref StreamObj): float64Reads a float64 from the stream
s.proc peekFloat64(s: ref StreamObj): float64Peeks a float64 from the stream
s.proc readStr(s: ref StreamObj; length: int64; str: var string)Reads a string of length
lengthfrom the streams.proc readStr(s: ref StreamObj; length: int64): stringReads a string of length
lengthfrom the streams.proc peekStr(s: ref StreamObj; length: int64; str: var string)Peeks a string of length
lengthfrom the streams.proc peekStr(s: ref StreamObj; length: int64): stringPeeks a string of length
lengthfrom the streams.proc readLine(s: ref StreamObj; line: var string): boolReads a line of text from the stream
sintoline. A line of text may be delimited byLForCRLF. The newline character(s) are not part of the returned string. Returnsfalseif the end of the file has been reached,trueotherwise.proc peekLine(s: ref StreamObj; line: var string): boolPeeks a line of text from the stream
sintoline.proc readLine(s: ref StreamObj): stringReads a line from a stream
s.proc peekLine(s: ref StreamObj): stringPeeks a line from a stream
s.iterator lines(s: ref StreamObj): stringIterates over every line in the stream.
type StringStream = ref StringStreamObjA stream that encapsulates a string.
type StringStreamObj = object data: string pos: int64
proc newStringStream(s: string): ref StringStreamObjCreates a new stream from the string
s.type FileStream = ref FileStreamObjA stream that encapsulates a
File.type FileStreamObj = object f: ref FileObj
proc newFileStream(f: ref FileObj): ref FileStreamObjCreates a new stream from the file
f.proc newFileStream(filename: string; mode: FileMode; bufSize: int64): ref FileStreamObjCreates a new stream from the file named
filenamewith the modemode. If the file cannot be opened,nilis returned.proc openFileStream(filename: string; mode: FileMode; bufSize: int64): ref FileStreamObjCreates a new stream from the file named
filenamewith the modemode. If the file cannot be opened, an IO error is raised.