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
-
NpgsqlLargeObjectStream
- Implements
- Inherited Members
Properties
CanRead
CanRead always returns true, unless the stream has been closed.
public override bool CanRead { get; }
Property Value
CanSeek
CanSeek always returns true, unless the stream has been closed.
public override bool CanSeek { get; }
Property Value
CanTimeout
CanTimeout always returns false.
public override bool CanTimeout { get; }
Property Value
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
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
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
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
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
boolWhether 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
CancellationTokenAn optional token to cancel the asynchronous operation. The default value is None.
Returns
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
intThe offset in the buffer where the first byte should be read.
count
intThe 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
intThe offset in the buffer where the first byte should be read.
count
intThe maximum number of bytes that should be read.
cancellationToken
CancellationTokenAn optional token to cancel the asynchronous operation. The default value is None.
Returns
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
longA byte offset relative to the origin parameter.
origin
SeekOriginA value of type SeekOrigin indicating the reference point used to obtain the new position.
Returns
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
longA byte offset relative to the origin parameter.
origin
SeekOriginA value of type SeekOrigin indicating the reference point used to obtain the new position.
cancellationToken
CancellationTokenAn optional token to cancel the asynchronous operation. The default value is None.
Returns
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
longNumber 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
longNumber of bytes to either truncate or enlarge the large object.
cancellationToken
CancellationTokenAn optional token to cancel the asynchronous operation. The default value is None.
Returns
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
intThe offset in the buffer at which to begin copying bytes.
count
intThe 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
intThe offset in the buffer at which to begin copying bytes.
count
intThe number of bytes to write.
cancellationToken
CancellationTokenAn optional token to cancel the asynchronous operation. The default value is None.