blobFromFile method

Future<void> blobFromFile({
  1. required FbBlobId id,
  2. required File file,
})

Fills a blob with data from the provided file.

The blob id has to correspond with a previously created blob. The size of the chunks read from the file is not controlled by FbDb (the file is opened with File.openRead, which provides a stream that spits buffers of various sizes, depending on the actual speed and availability of the file data).

Example:

final db = await FbDb.attach(host: "localhost", database: "employee");
await db.startTransaction(); // remember to start an explicit transaction
final blobId = await db.createBlob();
await db.blobFromFile(
  id: blobId,
  file: File("data.bin"),
);
final q = db.query();
// suppose TEST_TABLE.BLOB_COL contains blobs
await q.execute(
  sql: "insert into TEST_TABLE(BLOB_COL) values (?)",
  parameters: [blobId], // just the id, not the data
);
await db.commit(); // commit the started transaction
await db.detach();

Implementation

Future<void> blobFromFile({required FbBlobId id, required File file}) async {
  return putBlobFromStream(
    id: id,
    stream: file.openRead().map(
      (byteValues) => Uint8List.fromList(byteValues).buffer,
    ),
  );
}