Show / Hide Table of Contents

Class NpgsqlLargeObjectStream

An interface to remotely control the seekable stream for an opened large object on a PostgreSQL server. Note that the OpenRead/OpenReadWrite method as well as all operations performed on this stream must be wrapped inside a database transaction.

Inheritance
System.Object
System.MarshalByRefObject
System.IO.Stream
NpgsqlLargeObjectStream
Implements
System.IDisposable
Inherited Members
System.IO.Stream.Null
System.IO.Stream.CopyToAsync(System.IO.Stream)
System.IO.Stream.CopyToAsync(System.IO.Stream, System.Int32)
System.IO.Stream.CopyToAsync(System.IO.Stream, System.Int32, System.Threading.CancellationToken)
System.IO.Stream.CopyTo(System.IO.Stream)
System.IO.Stream.CopyTo(System.IO.Stream, System.Int32)
System.IO.Stream.Dispose()
System.IO.Stream.FlushAsync()
System.IO.Stream.FlushAsync(System.Threading.CancellationToken)
System.IO.Stream.CreateWaitHandle()
System.IO.Stream.BeginRead(System.Byte[], System.Int32, System.Int32, System.AsyncCallback, System.Object)
System.IO.Stream.EndRead(System.IAsyncResult)
System.IO.Stream.ReadAsync(System.Byte[], System.Int32, System.Int32)
System.IO.Stream.BeginWrite(System.Byte[], System.Int32, System.Int32, System.AsyncCallback, System.Object)
System.IO.Stream.EndWrite(System.IAsyncResult)
System.IO.Stream.WriteAsync(System.Byte[], System.Int32, System.Int32)
System.IO.Stream.ReadByte()
System.IO.Stream.WriteByte(System.Byte)
System.IO.Stream.Synchronized(System.IO.Stream)
System.IO.Stream.ObjectInvariant()
System.IO.Stream.ReadTimeout
System.IO.Stream.WriteTimeout
System.MarshalByRefObject.MemberwiseClone(System.Boolean)
System.MarshalByRefObject.GetLifetimeService()
System.MarshalByRefObject.InitializeLifetimeService()
System.MarshalByRefObject.CreateObjRef(System.Type)
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: Npgsql
Assembly: Npgsql.dll
Syntax
public sealed class NpgsqlLargeObjectStream : Stream, IDisposable

Properties

CanRead

CanRead always returns true, unless the stream has been closed.

Declaration
public override bool CanRead { get; }
Property Value
Type Description
System.Boolean
Overrides
System.IO.Stream.CanRead

CanSeek

CanSeek always returns true, unless the stream has been closed.

Declaration
public override bool CanSeek { get; }
Property Value
Type Description
System.Boolean
Overrides
System.IO.Stream.CanSeek

CanTimeout

CanTimeout always returns false.

Declaration
public override bool CanTimeout { get; }
Property Value
Type Description
System.Boolean
Overrides
System.IO.Stream.CanTimeout

CanWrite

CanWrite returns true if the stream was opened with write permissions, and the stream has not been closed.

Declaration
public override bool CanWrite { get; }
Property Value
Type Description
System.Boolean
Overrides
System.IO.Stream.CanWrite

Has64BitSupport

Since PostgreSQL 9.3, large objects larger than 2GB can be handled, up to 4TB. This property returns true whether the PostgreSQL version is >= 9.3.

Declaration
public bool Has64BitSupport { get; }
Property Value
Type Description
System.Boolean

Length

Gets the length of the large object. This internally seeks to the end of the stream to retrieve the length, and then back again.

Declaration
public override long Length { get; }
Property Value
Type Description
System.Int64
Overrides
System.IO.Stream.Length

Position

Returns the current position in the stream. Getting the current position does not need a round-trip to the server, however setting the current position does.

Declaration
public override long Position { get; set; }
Property Value
Type Description
System.Int64
Overrides
System.IO.Stream.Position

Methods

Close()

Releases resources at the backend allocated for this stream.

Declaration
public override void Close()
Overrides
System.IO.Stream.Close()

Dispose(Boolean)

Releases resources at the backend allocated for this stream, iff disposing is true.

Declaration
protected override void Dispose(bool disposing)
Parameters
Type Name Description
System.Boolean disposing

Whether to release resources allocated at the backend.

Overrides
System.IO.Stream.Dispose(System.Boolean)

Flush()

Does nothing.

Declaration
public override void Flush()
Overrides
System.IO.Stream.Flush()

GetLengthAsync()

Gets the length of the large object. This internally seeks to the end of the stream to retrieve the length, and then back again.

Declaration
public Task<long> GetLengthAsync()
Returns
Type Description
System.Threading.Tasks.Task<System.Int64>

GetLengthAsync(CancellationToken)

Gets the length of the large object. This internally seeks to the end of the stream to retrieve the length, and then back again.

Declaration
public Task<long> GetLengthAsync(CancellationToken cancellationToken)
Parameters
Type Name Description
System.Threading.CancellationToken cancellationToken

The token to monitor for cancellation requests. The default value is System.Threading.CancellationToken.None.

Returns
Type Description
System.Threading.Tasks.Task<System.Int64>

Read(Byte[], Int32, Int32)

Reads count bytes from the large object. The only case when fewer bytes are read is when end of stream is reached.

Declaration
public override int Read(byte[] buffer, int offset, int count)
Parameters
Type Name Description
System.Byte[] buffer

The buffer where read data should be stored.

System.Int32 offset

The offset in the buffer where the first byte should be read.

System.Int32 count

The maximum number of bytes that should be read.

Returns
Type Description
System.Int32

How many bytes actually read, or 0 if end of file was already reached.

Overrides
System.IO.Stream.Read(System.Byte[], System.Int32, System.Int32)

ReadAsync(Byte[], Int32, Int32, CancellationToken)

Reads count bytes from the large object. The only case when fewer bytes are read is when end of stream is reached.

Declaration
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
Parameters
Type Name Description
System.Byte[] buffer

The buffer where read data should be stored.

System.Int32 offset

The offset in the buffer where the first byte should be read.

System.Int32 count

The maximum number of bytes that should be read.

System.Threading.CancellationToken cancellationToken

The token to monitor for cancellation requests. The default value is System.Threading.CancellationToken.None.

Returns
Type Description
System.Threading.Tasks.Task<System.Int32>

How many bytes actually read, or 0 if end of file was already reached.

Overrides
System.IO.Stream.ReadAsync(System.Byte[], System.Int32, System.Int32, System.Threading.CancellationToken)

Seek(Int64, SeekOrigin)

Seeks in the stream to the specified position. This requires a round-trip to the backend.

Declaration
public override long Seek(long offset, SeekOrigin origin)
Parameters
Type Name Description
System.Int64 offset

A byte offset relative to the origin parameter.

System.IO.SeekOrigin origin

A value of type SeekOrigin indicating the reference point used to obtain the new position.

Returns
Type Description
System.Int64
Overrides
System.IO.Stream.Seek(System.Int64, System.IO.SeekOrigin)

SeekAsync(Int64, SeekOrigin, CancellationToken)

Seeks in the stream to the specified position. This requires a round-trip to the backend.

Declaration
public Task<long> SeekAsync(long offset, SeekOrigin origin, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type Name Description
System.Int64 offset

A byte offset relative to the origin parameter.

System.IO.SeekOrigin origin

A value of type SeekOrigin indicating the reference point used to obtain the new position.

System.Threading.CancellationToken cancellationToken

The token to monitor for cancellation requests. The default value is System.Threading.CancellationToken.None.

Returns
Type Description
System.Threading.Tasks.Task<System.Int64>

SetLength(Int64)

Truncates or enlarges the large object to the given size. If enlarging, the large object is extended with null bytes. For PostgreSQL versions earlier than 9.3, the value must fit in an Int32.

Declaration
public override void SetLength(long value)
Parameters
Type Name Description
System.Int64 value

Number of bytes to either truncate or enlarge the large object.

Overrides
System.IO.Stream.SetLength(System.Int64)

SetLength(Int64, CancellationToken)

Truncates or enlarges the large object to the given size. If enlarging, the large object is extended with null bytes. For PostgreSQL versions earlier than 9.3, the value must fit in an Int32.

Declaration
public Task SetLength(long value, CancellationToken cancellationToken)
Parameters
Type Name Description
System.Int64 value

Number of bytes to either truncate or enlarge the large object.

System.Threading.CancellationToken cancellationToken

Cancellation token.

Returns
Type Description
System.Threading.Tasks.Task

Write(Byte[], Int32, Int32)

Writes count bytes to the large object.

Declaration
public override void Write(byte[] buffer, int offset, int count)
Parameters
Type Name Description
System.Byte[] buffer

The buffer to write data from.

System.Int32 offset

The offset in the buffer at which to begin copying bytes.

System.Int32 count

The number of bytes to write.

Overrides
System.IO.Stream.Write(System.Byte[], System.Int32, System.Int32)

WriteAsync(Byte[], Int32, Int32, CancellationToken)

Writes count bytes to the large object.

Declaration
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
Parameters
Type Name Description
System.Byte[] buffer

The buffer to write data from.

System.Int32 offset

The offset in the buffer at which to begin copying bytes.

System.Int32 count

The number of bytes to write.

System.Threading.CancellationToken cancellationToken

The token to monitor for cancellation requests. The default value is System.Threading.CancellationToken.None.

Returns
Type Description
System.Threading.Tasks.Task
Overrides
System.IO.Stream.WriteAsync(System.Byte[], System.Int32, System.Int32, System.Threading.CancellationToken)

Implements

System.IDisposable
In This Article
Back to top Generated by DocFX