base class · System.IO
Stream
public base class Stream
A sequence of bytes. A stream says what it can do (CanRead, CanWrite, CanSeek); what it cannot do throws IOError.
- Kind
- base class
- Namespace
- System.IO
- Assembly
- System.Core
- Access
- public, abstract
- Source file
Stream.ant
Inheritance
- Base classes
-
AnyStream - Derived types
-
BufferedStreamFileStreamHandleStreamMemoryStream
Properties
How many bytes it has (streams that can seek).
Where the next byte is read or written (streams that can seek).
Methods
Reads up to count bytes into buffer[offset..]: how many (0 only at the end).
Writes buffer[offset..offset + count].
virtual Seek(i64 offset, SeekOrigin origin) : i64
#
Moves to offset from origin: the new position.
Makes it length bytes long (cutting or adding zeros).
virtual Flush()
#
Sends what is buffered to where the stream ends up.
virtual Close()
#
Flushes and lets go of what the stream holds; using it afterwards throws.
The next byte (0–255), or -1 at the end.
Reads up to buffer.Length bytes: how many (0 only at the end).
Reads exactly count bytes into buffer[offset..] (EndOfStreamError if the stream ends first).
Everything from the position to the end.
Copies everything from the position to the end into destination.
Inherited members (5)
GetTypemethod from AnyUndescribedmethod from AnyToStringmethod from AnyHashmethod from Anydestroymethod from Any
Source
Stream as Antril, decompiled from its Larva HIR.
// System.IO.Stream — System.Core (decompiled from Larva HIR)
into namespace System.IO
{
/// A sequence of bytes. A stream says what it can do (CanRead, CanWrite, CanSeek); what it cannot do throws IOError.
public base class Stream
{
public:
/// Reads up to `count` bytes into buffer[offset..]: how many (0 only at the end).
virtual Read(u8[] buffer, i32 offset, i32 count) : i32
{
throw new IOError("the stream cannot be read");
}
/// Writes buffer[offset..offset + count].
virtual Write(u8[] buffer, i32 offset, i32 count)
{
throw new IOError("the stream cannot be written");
}
/// Moves to `offset` from `origin`: the new position.
virtual Seek(i64 offset, SeekOrigin origin) : i64
{
throw new IOError("the stream cannot seek");
}
/// Makes it `length` bytes long (cutting or adding zeros).
virtual SetLength(i64 length)
{
throw new IOError("the stream cannot change its length");
}
/// Sends what is buffered to where the stream ends up.
virtual Flush()
{
}
/// Flushes and lets go of what the stream holds; using it afterwards throws.
virtual Close()
{
}
/// The next byte (0–255), or -1 at the end.
virtual ReadByte() : i32
{
u8[] one = new u8[1];
return Read(one, 0, 1) == 0 ? -1 : (i32)one[0];
}
virtual WriteByte(u8 value)
{
u8[] one = new u8[1];
one[0] = value;
Write(one, 0, 1);
}
/// Reads up to buffer.Length bytes: how many (0 only at the end).
Read(u8[] buffer) : i32 => Read(buffer, 0, buffer.Length);
Write(u8[] buffer)
{
Write(buffer, 0, buffer.Length);
}
/// Reads exactly `count` bytes into buffer[offset..] (EndOfStreamError if the stream ends first).
ReadExactly(u8[] buffer, i32 offset, i32 count)
{
loop (count > 0)
{
i32 read = Read(buffer, offset, count);
if (read == 0)
throw new EndOfStreamError();
offset += read;
count -= read;
}
}
/// Everything from the position to the end.
ReadToEnd() : u8[]
{
MemoryStream all = new MemoryStream();
CopyTo(all);
return all.ToArray();
}
/// Copies everything from the position to the end into `destination`.
CopyTo(Stream destination)
{
CopyTo(destination, 81920);
}
CopyTo(Stream destination, i32 bufferSize)
{
u8[] buffer = new u8[bufferSize];
i32 read = Read(buffer, 0, bufferSize);
loop (read > 0)
{
destination.Write(buffer, 0, read);
read = Read(buffer, 0, bufferSize);
}
}
virtual bool CanRead
{
get => false;
}
virtual bool CanWrite
{
get => false;
}
virtual bool CanSeek
{
get => false;
}
/// How many bytes it has (streams that can seek).
virtual i64 Length
{
get
{
throw new IOError("the stream has no length");
}
}
/// Where the next byte is read or written (streams that can seek).
virtual i64 Position
{
get
{
throw new IOError("the stream has no position");
}
set
{
throw new IOError("the stream has no position");
}
}
}
}