/*! * Copyright (c) Microsoft Corporation and contributors. All rights reserved. * Licensed under the MIT License. */ import { bufferToString } from "@fluid-internal/client-utils"; import type { IFluidHandle } from "@fluidframework/core-interfaces"; import type { IChannelStorageService, Serializable, } from "@fluidframework/datastore-definitions/internal"; import { BlobTreeEntry } from "@fluidframework/driver-utils/internal"; import type { IFluidSerializer } from "@fluidframework/shared-object-base/internal"; export const serializeBlob = ( handle: IFluidHandle, path: string, snapshot: Serializable, serializer: IFluidSerializer, ): BlobTreeEntry => new BlobTreeEntry(path, serializer.stringify(snapshot, handle)); export async function deserializeBlob( storage: IChannelStorageService, path: string, serializer: IFluidSerializer, // Allowing parsed content to remain in its original (any) form. // eslint-disable-next-line @typescript-eslint/no-explicit-any ): Promise { const blob = await storage.readBlob(path); const utf8 = bufferToString(blob, "utf8"); return serializer.parse(utf8); }