@transcend-io/penumbra
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -14,3 +14,3 @@ /// <reference types="node" /> | ||
} | ||
export declare function downloadEncryptedFile(url: string, key: string, iv: string, authTag: string, options?: DownloadEncryptedFileOptions): Promise<void>; | ||
export declare function downloadEncryptedFile(url: string, key: string | Buffer, iv: string | Buffer, authTag: string | Buffer, options?: DownloadEncryptedFileOptions): Promise<void>; | ||
/** | ||
@@ -17,0 +17,0 @@ * Download, decrypt, and return string, object URL, or Blob to display directly on the webpage |
@@ -85,3 +85,3 @@ "use strict"; | ||
}); | ||
window.dispatchEvent(event); | ||
self.dispatchEvent(event); | ||
} | ||
@@ -101,3 +101,3 @@ /** | ||
// TransformStreams are supported | ||
if ('TransformStream' in window) { | ||
if ('TransformStream' in self) { | ||
return rs.pipeThrough(new TransformStream({ | ||
@@ -151,3 +151,3 @@ transform: function (chunk, controller) { return __awaiter(_this, void 0, void 0, function () { | ||
// Feature detection for WritableStream - streams straight to disk | ||
if ('WritableStream' in window) | ||
if ('WritableStream' in self) | ||
return saveFileStream(rs, fileName); | ||
@@ -154,0 +154,0 @@ // No WritableStream; load into memory with a Blob |
35
index.ts
@@ -10,2 +10,3 @@ // External modules | ||
/** | ||
@@ -20,5 +21,5 @@ * Fetches an encrypted file from a URL deciphers it, and returns a ReadableStream | ||
function fetchAndDecipher( | ||
url: string, | ||
key: string | Buffer, | ||
iv: string | Buffer, | ||
url: string, | ||
key: string | Buffer, | ||
iv: string | Buffer, | ||
authTag: string | Buffer, | ||
@@ -72,3 +73,3 @@ ): Promise<ReadableStream> { | ||
}); | ||
window.dispatchEvent(event); | ||
self.dispatchEvent(event); | ||
} | ||
@@ -86,5 +87,5 @@ | ||
function decryptStream( | ||
rs: ReadableStream, | ||
decipher: Decipher, | ||
contentLength: number, | ||
rs: ReadableStream, | ||
decipher: Decipher, | ||
contentLength: number, | ||
url: string, | ||
@@ -97,3 +98,3 @@ ): ReadableStream { | ||
// TransformStreams are supported | ||
if ('TransformStream' in window) { | ||
if ('TransformStream' in self) { | ||
return rs.pipeThrough( | ||
@@ -153,7 +154,7 @@ new TransformStream({ | ||
function saveFile( | ||
rs: ReadableStream, | ||
rs: ReadableStream, | ||
fileName: string, | ||
): void | Promise<void> { | ||
// Feature detection for WritableStream - streams straight to disk | ||
if ('WritableStream' in window) return saveFileStream(rs, fileName); | ||
if ('WritableStream' in self) return saveFileStream(rs, fileName); | ||
@@ -236,6 +237,6 @@ // No WritableStream; load into memory with a Blob | ||
export async function downloadEncryptedFile( | ||
url: string, | ||
key: string, | ||
iv: string, | ||
authTag: string, | ||
url: string, | ||
key: string | Buffer, | ||
iv: string | Buffer, | ||
authTag: string | Buffer, | ||
options: DownloadEncryptedFileOptions = {} | ||
@@ -247,3 +248,3 @@ ): Promise<void> { | ||
const rs = await fetchAndDecipher(url, key, iv, authTag); | ||
// Stream the file to disk | ||
@@ -276,4 +277,4 @@ return saveFile(rs, fileName); | ||
if (type === 'image' || type === 'video' || type === 'audio') return getMediaSrcFromRS(rs); | ||
if (type === 'text' || mime === 'application/json') return getTextFromRS(rs); | ||
if (type === 'text' || mime === 'application/json') return getTextFromRS(rs); | ||
return new Response(rs).blob(); | ||
} | ||
} |
{ | ||
"name": "@transcend-io/penumbra", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Crypto streams for the browser.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29803
532