# Class NpgsqlLargeObjectStream

Namespace
  Npgsql

Assembly
  Npgsql.dll

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.

    [Obsolete("NpgsqlLargeObjectStream allows manipulating PostgreSQL large objects via publicly available PostgreSQL functions (lo_read, lo_write); call these yourself directly.")]
    public sealed class NpgsqlLargeObjectStream : Stream, IAsyncDisposable, IDisposable

Inheritance
  object
  MarshalByRefObject
  Stream
  NpgsqlLargeObjectStream

Implements
  IAsyncDisposable
  IDisposable

Inherited Members
  Stream.Null
  Stream.BeginRead(byte[], int, int, AsyncCallback, object)
  Stream.BeginWrite(byte[], int, int, AsyncCallback, object)
  Stream.CopyTo(Stream)
  Stream.CopyTo(Stream, int)
  Stream.CopyToAsync(Stream)
  Stream.CopyToAsync(Stream, int)
  Stream.CopyToAsync(Stream, int, CancellationToken)
  Stream.CopyToAsync(Stream, CancellationToken)
  Stream.Dispose()
  Stream.DisposeAsync()
  Stream.EndRead(IAsyncResult)
  Stream.EndWrite(IAsyncResult)
  Stream.FlushAsync()
  Stream.FlushAsync(CancellationToken)
  Stream.Read(Span<byte>)
  Stream.ReadAsync(byte[], int, int)
  Stream.ReadAsync(Memory<byte>, CancellationToken)
  Stream.ReadAtLeast(Span<byte>, int, bool)
  Stream.ReadAtLeastAsync(Memory<byte>, int, bool, CancellationToken)
  Stream.ReadByte()
  Stream.ReadExactly(byte[], int, int)
  Stream.ReadExactly(Span<byte>)
  Stream.ReadExactlyAsync(byte[], int, int, CancellationToken)
  Stream.ReadExactlyAsync(Memory<byte>, CancellationToken)
  Stream.Synchronized(Stream)
  Stream.Write(ReadOnlySpan<byte>)
  Stream.WriteAsync(byte[], int, int)
  Stream.WriteAsync(ReadOnlyMemory<byte>, CancellationToken)
  Stream.WriteByte(byte)
  Stream.ReadTimeout
  Stream.WriteTimeout
  MarshalByRefObject.GetLifetimeService()
  MarshalByRefObject.InitializeLifetimeService()
  object.Equals(object)
  object.Equals(object, object)
  object.GetHashCode()
  object.GetType()
  object.ReferenceEquals(object, object)
  object.ToString()

## Properties

### CanRead

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

    public override bool CanRead { get; }

#### Property Value

bool

### CanSeek

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

    public override bool CanSeek { get; }

#### Property Value

bool

### CanTimeout

CanTimeout always returns false.

    public override bool CanTimeout { get; }

#### Property Value

bool

### CanWrite

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

    public override bool CanWrite { get; }

#### Property Value

bool

### 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.

    public bool Has64BitSupport { get; }

#### Property Value

bool

### 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.

    public override long Length { get; }

#### Property Value

long

### 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.

    public override long Position { get; set; }

#### Property Value

long

## Methods

### Close()

Releases resources at the backend allocated for this stream.

    public override void Close()

### Dispose(bool)

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

    protected override void Dispose(bool disposing)

#### Parameters

`disposing` bool

  Whether to release resources allocated at the backend.

### Flush()

Does nothing.

    public override void Flush()

### 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.

    public Task<long> GetLengthAsync(CancellationToken cancellationToken = default)

#### Parameters

`cancellationToken` CancellationToken

  An optional token to cancel the asynchronous operation. The default value is None.

#### Returns

Task<long>

### Read(byte[], int, int)

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

    public override int Read(byte[] buffer, int offset, int count)

#### Parameters

`buffer` byte[]

  The buffer where read data should be stored.

`offset` int

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

`count` int

  The maximum number of bytes that should be read.

#### Returns

int

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

### ReadAsync(byte[], int, int, CancellationToken)

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

    public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)

#### Parameters

`buffer` byte[]

  The buffer where read data should be stored.

`offset` int

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

`count` int

  The maximum number of bytes that should be read.

`cancellationToken` CancellationToken

  An optional token to cancel the asynchronous operation. The default value is None.

#### Returns

Task<int>

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

### Seek(long, SeekOrigin)

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

    public override long Seek(long offset, SeekOrigin origin)

#### Parameters

`offset` long

  A byte offset relative to the origin parameter.

`origin` SeekOrigin

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

#### Returns

long

### SeekAsync(long, SeekOrigin, CancellationToken)

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

    public Task<long> SeekAsync(long offset, SeekOrigin origin, CancellationToken cancellationToken = default)

#### Parameters

`offset` long

  A byte offset relative to the origin parameter.

`origin` SeekOrigin

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

`cancellationToken` CancellationToken

  An optional token to cancel the asynchronous operation. The default value is None.

#### Returns

Task<long>

### SetLength(long)

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.

    public override void SetLength(long value)

#### Parameters

`value` long

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

### SetLength(long, 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.

    public Task SetLength(long value, CancellationToken cancellationToken)

#### Parameters

`value` long

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

`cancellationToken` CancellationToken

  An optional token to cancel the asynchronous operation. The default value is None.

#### Returns

Task

### Write(byte[], int, int)

Writes count bytes to the large object.

    public override void Write(byte[] buffer, int offset, int count)

#### Parameters

`buffer` byte[]

  The buffer to write data from.

`offset` int

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

`count` int

  The number of bytes to write.

### WriteAsync(byte[], int, int, CancellationToken)

Writes count bytes to the large object.

    public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)

#### Parameters

`buffer` byte[]

  The buffer to write data from.

`offset` int

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

`count` int

  The number of bytes to write.

`cancellationToken` CancellationToken

  An optional token to cancel the asynchronous operation. The default value is None.

#### Returns

Task