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.
Namespace: Npgsql
Assembly: Npgsql.dll
Syntax
public sealed class NpgsqlLargeObjectStream : Stream
Properties
| Improve this Doc View SourceCanRead
CanRead always returns true, unless the stream has been closed.
Declaration
public override bool CanRead { get; }
Property Value
Type | Description |
---|---|
bool |
CanSeek
CanSeek always returns true, unless the stream has been closed.
Declaration
public override bool CanSeek { get; }
Property Value
Type | Description |
---|---|
bool |
CanTimeout
CanTimeout always returns false.
Declaration
public override bool CanTimeout { get; }
Property Value
Type | Description |
---|---|
bool |
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 |
---|---|
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.
Declaration
public bool Has64BitSupport { get; }
Property Value
Type | Description |
---|---|
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.
Declaration
public override long Length { get; }
Property Value
Type | Description |
---|---|
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.
Declaration
public override long Position { get; set; }
Property Value
Type | Description |
---|---|
long |
Methods
| Improve this Doc View SourceClose()
Releases resources at the backend allocated for this stream.
Declaration
public override void Close()
Dispose(bool)
Releases resources at the backend allocated for this stream, iff disposing is true.
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing | Whether to release resources allocated at the backend. |
Flush()
Does nothing.
Declaration
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.
Declaration
public Task<long> GetLengthAsync(CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | An optional token to cancel the asynchronous operation. The default value is |
Returns
Type | Description |
---|---|
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.
Declaration
public override int Read(byte[] buffer, int offset, int count)
Parameters
Type | Name | Description |
---|---|---|
byte[] | buffer | The buffer where read data should be stored. |
int | offset | The offset in the buffer where the first byte should be read. |
int | count | The maximum number of bytes that should be read. |
Returns
Type | Description |
---|---|
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.
Declaration
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
byte[] | buffer | The buffer where read data should be stored. |
int | offset | The offset in the buffer where the first byte should be read. |
int | count | The maximum number of bytes that should be read. |
CancellationToken | cancellationToken | An optional token to cancel the asynchronous operation. The default value is |
Returns
Type | Description |
---|---|
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.
Declaration
public override long Seek(long offset, SeekOrigin origin)
Parameters
Type | Name | Description |
---|---|---|
long | offset | A byte offset relative to the origin parameter. |
SeekOrigin | origin | A value of type SeekOrigin indicating the reference point used to obtain the new position. |
Returns
Type | Description |
---|---|
long |
SeekAsync(long, 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 = null)
Parameters
Type | Name | Description |
---|---|---|
long | offset | A byte offset relative to the origin parameter. |
SeekOrigin | origin | 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 |
Returns
Type | Description |
---|---|
Task<><long> |
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.
Declaration
public Task SetLength(long value, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
long | value | 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 |
Returns
Type | Description |
---|---|
Task |
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.
Declaration
public override void SetLength(long value)
Parameters
Type | Name | Description |
---|---|---|
long | value | Number of bytes to either truncate or enlarge the large object. |
Write(byte[], int, int)
Writes count bytes to the large object.
Declaration
public override void Write(byte[] buffer, int offset, int count)
Parameters
Type | Name | Description |
---|---|---|
byte[] | buffer | The buffer to write data from. |
int | offset | The offset in the buffer at which to begin copying bytes. |
int | count | The number of bytes to write. |
WriteAsync(byte[], int, int, 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 |
---|---|---|
byte[] | buffer | The buffer to write data from. |
int | offset | The offset in the buffer at which to begin copying bytes. |
int | count | The number of bytes to write. |
CancellationToken | cancellationToken | An optional token to cancel the asynchronous operation. The default value is |
Returns
Type | Description |
---|---|
Task |