DuckDbStreamToByteArrayPropertyHandler
A property handler that maps a DuckDB BLOB column onto a byte array property.
A property handler that maps a DuckDB BLOB column onto a byte[] property. DuckDB.NET returns an unmanaged Stream when reading a BLOB value, which has no built-in coercion to byte[]. Writing is unaffected — a byte[] parameter value is already accepted natively by DuckDB.NET, so only the read direction needs this handler.
DuckDbBootstrap registers this handler at the type level keyed by
Stream— the CLR type DuckDB.NET’s reader reports for aBLOBcolumn — rather than bybyte[]. RepoDb.Core falls back to a type-level handler keyed by the reader’s reported type whenever a property has no explicit (attribute or property-level) handler of its own, so anybyte[]-typed property reading from aBLOBcolumn is converted automatically, with no attribute or manual mapping required.
Overview
| Name | Description |
|---|---|
| Class | DuckDbStreamToByteArrayPropertyHandler |
| Namespace | RepoDb.PropertyHandlers.DuckDb |
| Package | RepoDb.DuckDb |
| Implements | IPropertyHandler<object, byte[]> |
| Column type | The DuckDB BLOB type |
| Property type | byte[] |
Conversions
| Method | Direction | Description |
|---|---|---|
| Get | Database to property | Returns the value as-is when it is already a byte[]; copies the Stream returned by the driver into a byte[] otherwise. Returns an empty array when the value is neither. |
| Set | Property to database | Passes the byte[] through unchanged, to be written into a BLOB column. |
Usability
public class Document
{
public int Id { get; set; }
public byte[] Content { get; set; }
}
using (var connection = new DuckDBConnection(ConnectionString))
{
connection.Insert(new Document { Id = 1, Content = File.ReadAllBytes("file.pdf") });
var document = connection.Query<Document>(e => e.Id == 1).First();
}
To override the default registration:
PropertyHandlerMapper.Add<Stream, MyCustomStreamToByteArrayPropertyHandler>(new MyCustomStreamToByteArrayPropertyHandler(), true);