Added raw byte array in storage

This commit is contained in:
didier amyot committed 2023-06-10 08:41:17 -04:00
1 parent b0fe9f308e
commit ce7b6ae523
2 files changed
+53 -17

No files matched your search

+27 -6
View File
@@ -53,15 +53,19 @@ Deno.test("DenoKVBlobService happy path", async (t) => {
const bs = new DenoKVBlobService(kv, 50);
function toUint8Array(s: string): Uint8Array{
return new TextEncoder().encode(s);
}
await t.step("read write small text", async () => {
await bs.persistBlob('0002', 'hello world');
await bs.persistBlob('0002', toUint8Array('hello world'));
const body = await bs.getBlob('0002');
assertEquals(body, 'hello world');
assertEquals(body, toUint8Array('hello world'));
assertEquals(await bs.getNumberOfBlobs('0002'), 1);
});
await t.step("read write large text", async () => {
const largeText = generateLargeText(33, 100);
const largeText = toUint8Array(generateLargeText(33, 100));
await bs.persistBlob('0001', largeText);
const body = await bs.getBlob('0001');
assertEquals(body, largeText);
@@ -128,7 +132,24 @@ Deno.test("DenoKVFileService happy path", async (t) => {
});
kv.close();
});
Deno.test("DenoKVFileService happy path with byte array", async (t) => {
const kv = await Deno.openKv(":memory:");
const fs: FileService = new DenoKVFileService(kv);
await t.step("Create and read 1 binary file", async () => {
const inputBody = new Uint8Array([240]);
const file = await fs.createFromFullBody('hello', inputBody);
assertEquals(file.path, 'hello');
assertEquals(file.bodySize, inputBody.length);
const bodyString = await fs.getFullBodyByPath('hello');
assertEquals(bodyString, new TextDecoder().decode(inputBody));
});
kv.close();
});