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 as the default, type-level handler for every byte[] property, so it applies automatically without any attribute or manual mapping. Pass addDefaultHandlers: false to UseDuckDb() to opt out and register your own byte[] handler instead.

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, either disable it via addDefaultHandlers: false before mapping your own, or force-overwrite it directly:

PropertyHandlerMapper.Add<byte[], MyCustomStreamToByteArrayPropertyHandler>(new MyCustomStreamToByteArrayPropertyHandler(), true);