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
Implements
Inherited Members
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
CanSeek
CanSeek always returns true, unless the stream has been closed.
Declaration
public override bool CanSeek { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Overrides
CanTimeout
CanTimeout always returns false.
Declaration
public override bool CanTimeout { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Overrides
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
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
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
Methods
Close()
Releases resources at the backend allocated for this stream.
Declaration
public override void Close()
Overrides
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
Flush()
Does nothing.
Declaration
public override void Flush()
Overrides
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
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
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
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
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
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 |