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.

Tipo
base class
Espacio de nombres
System.IO
Ensamblado
System.Core
Acceso
public, abstract
Archivo fuente
Stream.ant

Herencia

Clases base
Any Stream
Tipos derivados
BufferedStream FileStream HandleStream MemoryStream

Propiedades

virtual bool CanRead { get; }
#

read-only

virtual bool CanWrite { get; }
#

read-only

virtual bool CanSeek { get; }
#

read-only

virtual i64 Length { get; }
#

read-only

How many bytes it has (streams that can seek).

virtual i64 Position { get; set; }
#

Where the next byte is read or written (streams that can seek).

Métodos

virtual Read(u8[] buffer, i32 offset, i32 count) : i32
#

virtual

Reads up to count bytes into buffer[offset..]: how many (0 only at the end).

virtual Write(u8[] buffer, i32 offset, i32 count)
#

virtual

Writes buffer[offset..offset + count].

virtual Seek(i64 offset, SeekOrigin origin) : i64
#

virtual

Moves to offset from origin: the new position.

virtual SetLength(i64 length)
#

virtual

Makes it length bytes long (cutting or adding zeros).

virtual Flush()
#

virtual

Sends what is buffered to where the stream ends up.

virtual Close()
#

virtual

Flushes and lets go of what the stream holds; using it afterwards throws.

virtual ReadByte() : i32
#

virtual

The next byte (0–255), or -1 at the end.

virtual WriteByte(u8 value)
#

virtual

Read(u8[] buffer) : i32
#

Reads up to buffer.Length bytes: how many (0 only at the end).

Write(u8[] buffer)
#
ReadExactly(u8[] buffer, i32 offset, i32 count)
#

Reads exactly count bytes into buffer[offset..] (EndOfStreamError if the stream ends first).

ReadToEnd() : u8[]
#

Everything from the position to the end.

CopyTo(Stream destination)
#

Copies everything from the position to the end into destination.

CopyTo(Stream destination, i32 bufferSize)
#

Miembros heredados (5)

Código fuente

Stream en Antril, descompilado a partir de su Larva HIR.

System.IO.Stream.ant
// 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");
				}
			}
	}
}
Esc