Skip to content

The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.

587 B
Raw Blame
type SerializedBuffer = { type: "Buffer"; data: number[] | ArrayBuffer }

// The event bus serializes a Buffer to `{ type: "Buffer", data }`, and the
// signature has to be checked against the original bytes.
export function reviveRawData(rawData: unknown): string | Buffer | null {
  if ((rawData as SerializedBuffer | null)?.type === "Buffer") {
    const { data } = rawData as SerializedBuffer
    return Buffer.from(data instanceof ArrayBuffer ? new Uint8Array(data) : data)
  }
  if (typeof rawData === "string" || Buffer.isBuffer(rawData)) {
    return rawData
  }
  return null
}