( filename: string, key: SerializedKey, cipherData: FileEncryptionMetadataWithOutputType<TOutputFormat> )
| 189 | } |
| 190 | |
| 191 | async function readEncrypted<TOutputFormat extends DataFormat>( |
| 192 | filename: string, |
| 193 | key: SerializedKey, |
| 194 | cipherData: FileEncryptionMetadataWithOutputType<TOutputFormat> |
| 195 | ) { |
| 196 | const fileHandle = await streamablefs.readFile(filename); |
| 197 | if (!fileHandle) { |
| 198 | console.error(`File not found. (File hash: ${filename})`); |
| 199 | return; |
| 200 | } |
| 201 | const decryptionStream = await NNCrypto.createDecryptionStream( |
| 202 | key, |
| 203 | cipherData.iv |
| 204 | ); |
| 205 | |
| 206 | return ( |
| 207 | cipherData.outputType === "base64" || cipherData.outputType === "text" |
| 208 | ? ( |
| 209 | await consumeReadableStream( |
| 210 | fileHandle.readable |
| 211 | .pipeThrough(decryptionStream) |
| 212 | .pipeThrough( |
| 213 | cipherData.outputType === "text" |
| 214 | ? new globalThis.TextDecoderStream() |
| 215 | : new Base64DecoderStream() |
| 216 | ) |
| 217 | ) |
| 218 | ).join("") |
| 219 | : new Uint8Array( |
| 220 | Buffer.concat( |
| 221 | await consumeReadableStream( |
| 222 | fileHandle.readable.pipeThrough(decryptionStream) |
| 223 | ) |
| 224 | ) |
| 225 | ) |
| 226 | ) as Output<TOutputFormat>; |
| 227 | } |
| 228 | |
| 229 | type RequestOptionsWithSignal = RequestOptions & { |
| 230 | signal: AbortSignal; |
nothing calls this directly
no test coverage detected