(name: MemoryDocumentName, input: Uint8Array)
| 120 | } |
| 121 | |
| 122 | export function validateDocumentBytes(name: MemoryDocumentName, input: Uint8Array): Buffer { |
| 123 | if (!(input instanceof Uint8Array)) { |
| 124 | throw invalidMemoryDocument(`${displayName(name)} bytes are required`); |
| 125 | } |
| 126 | const bytes = Buffer.from(input); |
| 127 | if (bytes.byteLength > MEMORY_DOCUMENT_MAX_BYTES) { |
| 128 | throw invalidMemoryDocument( |
| 129 | `${displayName(name)} exceeds its ${MEMORY_DOCUMENT_MAX_BYTES} byte limit`, |
| 130 | ); |
| 131 | } |
| 132 | try { |
| 133 | new TextDecoder('utf-8', { fatal: true }).decode(bytes); |
| 134 | } catch (error) { |
| 135 | throw invalidMemoryDocument(`${displayName(name)} is not valid UTF-8`, error); |
| 136 | } |
| 137 | return bytes; |
| 138 | } |
| 139 | |
| 140 | export function bundleTarget( |
| 141 | memory: Buffer, |
no test coverage detected