Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More β†’
Socket
Sign inDemoInstall
Socket

torrefy

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

torrefy - npm Package Compare versions

Comparing version 2.0.2 to 2.0.3

dist/transformers/blockHasher.d.ts

145

dist/create.d.ts

@@ -1,2 +0,4 @@

import { BObject } from "./encode.js";
import { BObject } from "./utils/codec.js";
import { FilesList, FileTreeDirNode } from "./utils/fileTree.js";
import { FileDirLikes } from "./utils/fileDirLike.js";
/**

@@ -13,3 +15,3 @@ * support padding attribute on file

*/
declare type MetaVersion = 2;
type MetaVersion = 2;
/**

@@ -76,3 +78,3 @@ * torrent type: v1, v2, hybrid

/**
* piece length: a power of 2 number
* piece length: a power of 2 number,
* will automatically calculate when this value is missing

@@ -132,108 +134,7 @@ */

*/
export declare type TorrentOptions<T extends TorrentType | undefined = undefined> = T extends TorrentType.V1 ? TorrentOptionsV1 : T extends TorrentType.V2 ? TorrentOptionsV2 : T extends TorrentType.HYBRID ? TorrentOptionsHybrid : TorrentOptionsV1 | TorrentOptionsV2 | TorrentOptionsHybrid;
export type TorrentOptions<T extends TorrentType = TorrentType> = T extends TorrentType.V1 ? TorrentOptionsV1 : T extends TorrentType.V2 ? TorrentOptionsV2 : T extends TorrentType.HYBRID ? TorrentOptionsHybrid : never;
/**
* symlink file attribute
*/
declare type SymlinkAttr = "s";
/**
* executable file attribute
*/
declare type ExecutableAttr = "x";
/**
* hidden file attribute
*/
declare type HiddenAttr = "h";
/**
* padding file attribute
*/
declare type PaddingFileAttr = "p";
/**
* permutations template
*/
declare type Permutations<T extends string, U extends string = T> = T extends any ? T | `${T}${Permutations<Exclude<U, T>>}` : never;
/**
* file attributes
*/
export declare type FileAttrs = Permutations<SymlinkAttr | ExecutableAttr | HiddenAttr | PaddingFileAttr>;
/**
* base file props
*/
interface FilePropsBase extends BObject {
/**
* Length of the file in bytes
*
* [BEP 3](https://www.bittorrent.org/beps/bep_0003.html#:~:text=the%20following%20keys%3A-,length,-%2D%20The%20length%20of)
* |
* [BEP 52](https://www.bittorrent.org/beps/bep_0052.html#upgrade-path:~:text=pieces%20root32%3Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaeeeeeee-,length,-Length%20of%20the)
*/
length: number;
/**
* A variable-length string. When present,
* the characters each represent a file attribute:
* ```
* l = symlink
* x = executable
* h = hidden
* p = padding file
* ```
* [BEP 47](https://www.bittorrent.org/beps/bep_0047.html#:~:text=20%20bytes%3E%2C%0A%20%20%20%20...%0A%20%20%7D%2C%0A%20%20...%0A%7D-,attr,-A%20variable%2Dlength)
*/
attr?: FileAttrs;
}
/**
* v1 file props
*/
export interface FilePropsV1 extends FilePropsBase {
/**
* A list of UTF-8 encoded strings
* corresponding to **subdirectory** names
*
* [BEP 3](https://www.bittorrent.org/beps/bep_0003.html#:~:text=file%2C%20in%20bytes.-,path,-%2D%20A%20list%20of)
*/
path: string[];
}
/**
* v2 file props
*/
export interface FilePropsV2 extends FilePropsBase {
/**
* For **non-empty** files this is the the root hash
* of a merkle tree with a branching factor of 2,
* constructed from 16KiB blocks of the file
*
* [BEP 52](https://www.bittorrent.org/beps/bep_0052.html#:~:text=any%20sibling%20entries.-,pieces%20root,-For%20non%2Dempty)
*/
["pieces root"]?: ArrayBuffer;
}
/**
* v1 file list
*/
export declare type FilesList = FilePropsV1[];
/**
* v2 file node value
*/
export interface FileNodeValue extends BObject {
/**
* Entries with zero-length keys describe the properties
* of the composed path at that point
*
* [BEP 52](https://www.bittorrent.org/beps/bep_0052.html#:~:text=Entries%20with%20zero%2Dlength%20keys%20describe%20the%20properties%20of%20the%20composed%20path%20at%20that%20point)
*/
"": FilePropsV2;
}
/**
* v2 dir node value
*/
export interface DirNodeValue extends BObject {
[name: string]: DirNodeValue | FileNodeValue;
}
/**
* v2 file tree
*/
export interface FileTree extends DirNodeValue, Iterable<FileNodeValue> {
}
/**
* info base
*/
interface InfoBase extends BObject {
interface InfoBase extends BObject<false> {
/**

@@ -260,3 +161,3 @@ * The suggested name to save the file (or directory) as.

*/
private?: 0 | 1;
private?: boolean;
}

@@ -289,3 +190,3 @@ /**

*/
declare type InfoV1 = InfoV1SingleFile | InfoV1MultiFiles;
type InfoV1 = InfoV1SingleFile | InfoV1MultiFiles;
/**

@@ -301,3 +202,3 @@ * v2 info

*/
["file tree"]: FileTree;
["file tree"]: FileTreeDirNode;
/**

@@ -324,15 +225,15 @@ * An integer value, set to 2 to indicate compatibility

*/
declare type InfoHybrid = InfoHybridSingleFile | InfoHybridMultiFiles;
type InfoHybrid = InfoHybridSingleFile | InfoHybridMultiFiles;
/**
* info
*/
export declare type Info<T extends TorrentType | undefined = undefined> = T extends TorrentType.V1 ? InfoV1 : T extends TorrentType.V2 ? InfoV2 : T extends TorrentType.HYBRID ? InfoHybrid : InfoV1 | InfoV2 | InfoHybrid;
export type Info<T extends TorrentType = TorrentType> = T extends TorrentType.V1 ? InfoV1 : T extends TorrentType.V2 ? InfoV2 : T extends TorrentType.HYBRID ? InfoHybrid : never;
/**
* v2 piece layers
*/
export declare type PieceLayers = Map<ArrayBuffer, ArrayBuffer>;
export type PieceLayers = Map<ArrayBuffer, ArrayBuffer>;
/**
* base meta info
*/
interface MetaInfoBase extends BObject {
interface MetaInfoBase extends BObject<false> {
/**

@@ -389,4 +290,5 @@ * The URL of the tracker

*/
interface MetaInfoHybrid extends MetaInfoV2 {
interface MetaInfoHybrid extends MetaInfoBase {
info: Info<TorrentType.HYBRID>;
["piece layers"]?: PieceLayers;
}

@@ -396,3 +298,3 @@ /**

*/
export declare type MetaInfo<T extends TorrentType | undefined = undefined> = T extends TorrentType.V1 ? MetaInfoV1 : T extends TorrentType.V2 ? MetaInfoV2 : T extends TorrentType.HYBRID ? MetaInfoHybrid : MetaInfoV1 | MetaInfoV2 | MetaInfoHybrid;
export type MetaInfo<T extends TorrentType = TorrentType> = T extends TorrentType.V1 ? MetaInfoV1 : T extends TorrentType.V2 ? MetaInfoV2 : T extends TorrentType.HYBRID ? MetaInfoHybrid : never;
/**

@@ -419,11 +321,6 @@ * default block length 1 << 14 = 16384

}
export declare type OnProgress = (current: number, total: number) => void | Promise<void>;
/**
* Create a torrent, returns meta info
* @param files
* @param opts
* @param onProgress
* @returns
*/
export declare function create(files: File[], opts?: TorrentOptions, onProgress?: OnProgress): Promise<MetaInfo<TorrentType>>;
export type OnProgress = (current: number, total: number) => void | Promise<void>;
export declare function create(fileDirLikes: FileDirLikes, opts?: TorrentOptions, onProgress?: OnProgress): Promise<MetaInfoV1 | MetaInfoV2 | undefined>;
export type SetProgressTotal = (totalNumberOrFunction: number | ((total: number, current?: number) => number | Promise<number>)) => Promise<void>;
export type UpdateProgress = () => Promise<void>;
export {};

@@ -1,34 +0,4 @@

import { BData, BList, BObject } from "./encode.js";
declare enum TokenType {
Integer = "Integer",
ByteString = "ByteString",
ListStart = "ListStart",
ListEnd = "ListEnd",
DictionaryStart = "DictionaryStart",
DictionaryEnd = "DictionaryEnd"
}
interface IntegerToken {
type: TokenType.Integer;
value: Uint8Array;
}
interface ByteStringToken {
type: TokenType.ByteString;
value: Uint8Array;
}
interface ListStartToken {
type: TokenType.ListStart;
}
interface ListEndToken {
type: TokenType.ListEnd;
}
interface DictionaryStartToken {
type: TokenType.DictionaryStart;
}
interface DictionaryEndToken {
type: TokenType.DictionaryEnd;
}
declare type Token<T extends TokenType = TokenType> = T extends TokenType.Integer ? IntegerToken : T extends TokenType.ByteString ? ByteStringToken : T extends TokenType.ListStart ? ListStartToken : T extends TokenType.ListEnd ? ListEndToken : T extends TokenType.DictionaryStart ? DictionaryStartToken : T extends TokenType.DictionaryEnd ? DictionaryEndToken : IntegerToken | ByteStringToken | ListStartToken | ListEndToken | DictionaryStartToken | DictionaryEndToken;
export declare function makeTokenizer(): TransformStream<Uint8Array, IntegerToken | ByteStringToken | ListStartToken | ListEndToken | DictionaryStartToken | DictionaryEndToken>;
export declare function parse(tokenReadableStream: ReadableStream<Token>): Promise<string | number | bigint | BObject | BList | undefined>;
export declare function decode(torrentReadableStream: ReadableStream<Uint8Array>): Promise<BData>;
export {};
import { BData } from "./utils/codec.js";
import { Token } from "./transformers/tokenizer.js";
export declare function parse(tokenReadableStream: ReadableStream<Token>): Promise<BData | undefined>;
export declare function decode(torrentReadableStream: ReadableStream<Uint8Array>): Promise<BData | undefined>;

@@ -1,42 +0,12 @@

import ArrayKeyedMap from "array-keyed-map";
export { default as ArrayKeyedMap } from "array-keyed-map";
import { TrieMap } from "@sec-ant/trie-map";
import { BData } from "./utils/codec.js";
/**
* bencode list
*/
export declare type BList = BData[];
/**
* bencode object (as dictionary)
*/
export interface BObject {
[k: string]: BData;
}
/**
* bencode map (as dictionary)
*/
export declare type BMap = Map<ArrayBuffer | string, BData>;
/**
* allowed bencode data
*/
export declare type BData = boolean | number | bigint | string | ArrayBuffer | BList | BObject | BMap | undefined | null;
/**
* encode hook handler
*/
export declare type EncodeHookHandler = (result: IteratorResult<Uint8Array, undefined>) => void;
export type EncodeHookHandler = (result: IteratorResult<Uint8Array, undefined>) => void;
/**
* encoder hooks
*/
declare type EncoderHooks = ArrayKeyedMap<(string | ArrayBuffer)[], EncodeHookHandler>;
type EncoderHooks = TrieMap<Iterable<string | number>, EncodeHookHandler>;
/**
* bencode token: l (stands for list start)
*/
export declare const BUFF_L: Uint8Array;
/**
* bencode token: d (stands for dictionary start)
*/
export declare const BUFF_D: Uint8Array;
/**
* bencode token: e (stands for end)
*/
export declare const BUFF_E: Uint8Array;
/**
* BEncode

@@ -47,23 +17,18 @@ * @param data

*/
export declare function encode(data: BData, hooks?: EncoderHooks): ReadableStream<Uint8Array>;
export declare function encode(data: BData<false>, hooks?: EncoderHooks): ReadableStream<Uint8Array>;
/**
* Get a uint8 array stream hook handler
* @returns a uint8 array readable stream and a hook handler
* @returns a uint8 array readable stream
*/
export declare function useUint8ArrayStreamHook(): [
ReadableStream<Uint8Array>,
EncodeHookHandler
];
export declare function useUint8ArrayStreamHook(path: Iterable<string>, hooks: EncoderHooks): [ReadableStream<Uint8Array>];
/**
* Get an array buffer promise hook handler
* @returns an array buffer promise and a hook handler
* @returns an array buffer
*/
export declare function useArrayBufferPromiseHook(): [
Promise<ArrayBuffer>,
EncodeHookHandler
];
export declare function useArrayBufferPromiseHook(path: Iterable<string>, hooks: EncoderHooks): [Promise<ArrayBuffer>];
/**
* Get an text promise hook handler
* @returns an text promise and a hook handler
* @returns an text promise
*/
export declare function useTextPromiseHook(): [Promise<string>, EncodeHookHandler];
export declare function useTextPromiseHook(path: Iterable<string>, hooks: EncoderHooks): [Promise<string>];
export {};

@@ -1,4 +0,5 @@

export * from "./utils.js";
export * from "./encode.js";
export * from "./decode.js";
export * from "./create.js";
export * from "./transformers/index.js";
export * from "./utils/index.js";

@@ -1,1 +0,1 @@

var t={340:t=>{const e=Symbol("path-store-trunk");class n{constructor(t=[]){this._root=new Map,this._size=0;for(const[e,n]of t)this.set(e,n)}set(t,e){return r.call(this,t,e)}has(t){return o.call(this,t)}get(t){return s.call(this,t)}delete(t){return i.call(this,t)}get size(){return this._size}clear(){this._root.clear(),this._size=0}hasPrefix(t){return a.call(this,t)}get[Symbol.toStringTag](){return"ArrayKeyedMap"}*[Symbol.iterator](){yield*u.call(this)}*entries(){yield*u.call(this)}*keys(){yield*h.call(this)}*values(){yield*c.call(this)}forEach(t,e){f.call(this,t,e)}}function r(t,n){let r=this._root;for(const e of t){let t=r.get(e);t||(t=new Map,r.set(e,t)),r=t}return r.has(e)||(this._size+=1),r.set(e,n),this}function o(t){let n=this._root;for(const e of t){const t=n.get(e);if(!t)return!1;n=t}return n.has(e)}function s(t){let n=this._root;for(const e of t)if(n=n.get(e),!n)return;return n.get(e)}function i(t){let n=this._root;const r=[];for(const e of t){const t=n.get(e);if(!t)return!1;r.unshift({parent:n,child:t,item:e}),n=t}const o=n.delete(e);if(o){this._size-=1;for(const{parent:t,child:e,item:n}of r)0===e.size&&t.delete(n)}return o}function a(t){let e=this._root;for(const n of t)if(e=e.get(n),!e)return!1;return!0}function*u(){const t=[{path:[],map:this._root}];for(;t.length>0;){const{path:n,map:r}=t.pop();for(const[o,s]of r.entries())o===e?yield[n,s]:t.push({path:n.concat([o]),map:s})}}function*h(){for(const[t]of this.entries())yield t}function*c(){for(const[,t]of this.entries())yield t}function f(t,e){for(const[n,r]of this.entries())t.call(e,r,n,this)}t.exports=n},913:()=>{try{self["workbox:core:6.5.3"]&&_()}catch(t){}},1:()=>{try{self["workbox:streams:6.5.3"]&&_()}catch(t){}},211:(t,e,n)=>{n.r(e),n.d(e,{default:()=>y});const r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function o(t,e,n,r){let o,s,i;const a=e||[0],u=(n=n||0)>>>3,h=-1===r?3:0;for(o=0;o<t.length;o+=1)i=o+u,s=i>>>2,a.length<=s&&a.push(0),a[s]|=t[o]<<8*(h+r*(i%4));return{value:a,binLen:8*t.length+n}}function s(t,e,n){switch(e){case"UTF8":case"UTF16BE":case"UTF16LE":break;default:throw new Error("encoding must be UTF8, UTF16BE, or UTF16LE")}switch(t){case"HEX":return function(t,e,r){return function(t,e,n,r){let o,s,i,a;if(0!=t.length%2)throw new Error("String of HEX type must be in byte increments");const u=e||[0],h=(n=n||0)>>>3,c=-1===r?3:0;for(o=0;o<t.length;o+=2){if(s=parseInt(t.substr(o,2),16),isNaN(s))throw new Error("String of HEX type contains invalid characters");for(a=(o>>>1)+h,i=a>>>2;u.length<=i;)u.push(0);u[i]|=s<<8*(c+r*(a%4))}return{value:u,binLen:4*t.length+n}}(t,e,r,n)};case"TEXT":return function(t,r,o){return function(t,e,n,r,o){let s,i,a,u,h,c,f,l,p=0;const d=n||[0],g=(r=r||0)>>>3;if("UTF8"===e)for(f=-1===o?3:0,a=0;a<t.length;a+=1)for(s=t.charCodeAt(a),i=[],128>s?i.push(s):2048>s?(i.push(192|s>>>6),i.push(128|63&s)):55296>s||57344<=s?i.push(224|s>>>12,128|s>>>6&63,128|63&s):(a+=1,s=65536+((1023&s)<<10|1023&t.charCodeAt(a)),i.push(240|s>>>18,128|s>>>12&63,128|s>>>6&63,128|63&s)),u=0;u<i.length;u+=1){for(c=p+g,h=c>>>2;d.length<=h;)d.push(0);d[h]|=i[u]<<8*(f+o*(c%4)),p+=1}else for(f=-1===o?2:0,l="UTF16LE"===e&&1!==o||"UTF16LE"!==e&&1===o,a=0;a<t.length;a+=1){for(s=t.charCodeAt(a),!0===l&&(u=255&s,s=u<<8|s>>>8),c=p+g,h=c>>>2;d.length<=h;)d.push(0);d[h]|=s<<8*(f+o*(c%4)),p+=2}return{value:d,binLen:8*p+r}}(t,e,r,o,n)};case"B64":return function(t,e,o){return function(t,e,n,o){let s,i,a,u,h,c,f,l=0;const p=e||[0],d=(n=n||0)>>>3,g=-1===o?3:0,y=t.indexOf("=");if(-1===t.search(/^[a-zA-Z0-9=+/]+$/))throw new Error("Invalid character in base-64 string");if(t=t.replace(/=/g,""),-1!==y&&y<t.length)throw new Error("Invalid '=' found in base-64 string");for(i=0;i<t.length;i+=4){for(h=t.substr(i,4),u=0,a=0;a<h.length;a+=1)s=r.indexOf(h.charAt(a)),u|=s<<18-6*a;for(a=0;a<h.length-1;a+=1){for(f=l+d,c=f>>>2;p.length<=c;)p.push(0);p[c]|=(u>>>16-8*a&255)<<8*(g+o*(f%4)),l+=1}}return{value:p,binLen:8*l+n}}(t,e,o,n)};case"BYTES":return function(t,e,r){return function(t,e,n,r){let o,s,i,a;const u=e||[0],h=(n=n||0)>>>3,c=-1===r?3:0;for(s=0;s<t.length;s+=1)o=t.charCodeAt(s),a=s+h,i=a>>>2,u.length<=i&&u.push(0),u[i]|=o<<8*(c+r*(a%4));return{value:u,binLen:8*t.length+n}}(t,e,r,n)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(t){throw new Error("ARRAYBUFFER not supported by this environment")}return function(t,e,r){return function(t,e,n,r){return o(new Uint8Array(t),e,n,r)}(t,e,r,n)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(t){throw new Error("UINT8ARRAY not supported by this environment")}return function(t,e,r){return o(t,e,r,n)};default:throw new Error("format must be HEX, TEXT, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}function i(t,e,n,o){switch(t){case"HEX":return function(t){return function(t,e,n,r){const o="0123456789abcdef";let s,i,a="";const u=e/8,h=-1===n?3:0;for(s=0;s<u;s+=1)i=t[s>>>2]>>>8*(h+n*(s%4)),a+=o.charAt(i>>>4&15)+o.charAt(15&i);return r.outputUpper?a.toUpperCase():a}(t,e,n,o)};case"B64":return function(t){return function(t,e,n,o){let s,i,a,u,h,c="";const f=e/8,l=-1===n?3:0;for(s=0;s<f;s+=3)for(u=s+1<f?t[s+1>>>2]:0,h=s+2<f?t[s+2>>>2]:0,a=(t[s>>>2]>>>8*(l+n*(s%4))&255)<<16|(u>>>8*(l+n*((s+1)%4))&255)<<8|h>>>8*(l+n*((s+2)%4))&255,i=0;i<4;i+=1)c+=8*s+6*i<=e?r.charAt(a>>>6*(3-i)&63):o.b64Pad;return c}(t,e,n,o)};case"BYTES":return function(t){return function(t,e,n){let r,o,s="";const i=e/8,a=-1===n?3:0;for(r=0;r<i;r+=1)o=t[r>>>2]>>>8*(a+n*(r%4))&255,s+=String.fromCharCode(o);return s}(t,e,n)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(t){throw new Error("ARRAYBUFFER not supported by this environment")}return function(t){return function(t,e,n){let r;const o=e/8,s=new ArrayBuffer(o),i=new Uint8Array(s),a=-1===n?3:0;for(r=0;r<o;r+=1)i[r]=t[r>>>2]>>>8*(a+n*(r%4))&255;return s}(t,e,n)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(t){throw new Error("UINT8ARRAY not supported by this environment")}return function(t){return function(t,e,n){let r;const o=e/8,s=-1===n?3:0,i=new Uint8Array(o);for(r=0;r<o;r+=1)i[r]=t[r>>>2]>>>8*(s+n*(r%4))&255;return i}(t,e,n)};default:throw new Error("format must be HEX, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}function a(t){const e={outputUpper:!1,b64Pad:"=",outputLen:-1},n=t||{},r="Output length must be a multiple of 8";if(e.outputUpper=n.outputUpper||!1,n.b64Pad&&(e.b64Pad=n.b64Pad),n.outputLen){if(n.outputLen%8!=0)throw new Error(r);e.outputLen=n.outputLen}else if(n.shakeLen){if(n.shakeLen%8!=0)throw new Error(r);e.outputLen=n.shakeLen}if("boolean"!=typeof e.outputUpper)throw new Error("Invalid outputUpper formatting option");if("string"!=typeof e.b64Pad)throw new Error("Invalid b64Pad formatting option");return e}function u(t,e){return t<<e|t>>>32-e}function h(t,e,n){return t^e^n}function c(t,e,n){return t&e^t&n^e&n}function f(t,e){const n=(65535&t)+(65535&e);return(65535&(t>>>16)+(e>>>16)+(n>>>16))<<16|65535&n}function l(t,e,n,r,o){const s=(65535&t)+(65535&e)+(65535&n)+(65535&r)+(65535&o);return(65535&(t>>>16)+(e>>>16)+(n>>>16)+(r>>>16)+(o>>>16)+(s>>>16))<<16|65535&s}function p(t){return[1732584193,4023233417,2562383102,271733878,3285377520]}function d(t,e){let n,r,o,s,i,a,p;const d=[];for(n=e[0],r=e[1],o=e[2],s=e[3],i=e[4],p=0;p<80;p+=1)d[p]=p<16?t[p]:u(d[p-3]^d[p-8]^d[p-14]^d[p-16],1),a=p<20?l(u(n,5),(g=r)&o^~g&s,i,1518500249,d[p]):p<40?l(u(n,5),h(r,o,s),i,1859775393,d[p]):p<60?l(u(n,5),c(r,o,s),i,2400959708,d[p]):l(u(n,5),h(r,o,s),i,3395469782,d[p]),i=s,s=o,o=u(r,30),r=n,n=a;var g;return e[0]=f(n,e[0]),e[1]=f(r,e[1]),e[2]=f(o,e[2]),e[3]=f(s,e[3]),e[4]=f(i,e[4]),e}function g(t,e,n,r){let o;const s=15+(e+65>>>9<<4),i=e+n;for(;t.length<=s;)t.push(0);for(t[e>>>5]|=128<<24-e%32,t[s]=4294967295&i,t[s-1]=i/4294967296|0,o=0;o<t.length;o+=16)r=d(t.slice(o,o+16),r);return r}class y extends class{constructor(t,e,n){const r=n||{};if(this.t=e,this.i=r.encoding||"UTF8",this.numRounds=r.numRounds||1,isNaN(this.numRounds)||this.numRounds!==parseInt(this.numRounds,10)||1>this.numRounds)throw new Error("numRounds must a integer >= 1");this.o=t,this.h=[],this.u=0,this.l=!1,this.A=0,this.p=!1,this.R=[],this.U=[]}update(t){let e,n=0;const r=this.T>>>5,o=this.F(t,this.h,this.u),s=o.binLen,i=o.value,a=s>>>5;for(e=0;e<a;e+=r)n+this.T<=s&&(this.m=this.g(i.slice(e,e+r),this.m),n+=this.T);return this.A+=n,this.h=i.slice(n>>>5),this.u=s%this.T,this.l=!0,this}getHash(t,e){let n,r,o=this.B;const s=a(e);if(this.v){if(-1===s.outputLen)throw new Error("Output length must be specified in options");o=s.outputLen}const u=i(t,o,this.Y,s);if(this.p&&this.H)return u(this.H(s));for(r=this.C(this.h.slice(),this.u,this.A,this.I(this.m),o),n=1;n<this.numRounds;n+=1)this.v&&o%32!=0&&(r[r.length-1]&=16777215>>>24-o%32),r=this.C(r,o,0,this.L(this.o),o);return u(r)}setHMACKey(t,e,n){if(!this.M)throw new Error("Variant does not support HMAC");if(this.l)throw new Error("Cannot set MAC key after calling update");const r=s(e,(n||{}).encoding||"UTF8",this.Y);this.N(r(t))}N(t){const e=this.T>>>3,n=e/4-1;let r;if(1!==this.numRounds)throw new Error("Cannot set numRounds with MAC");if(this.p)throw new Error("MAC key already set");for(e<t.binLen/8&&(t.value=this.C(t.value,t.binLen,0,this.L(this.o),this.B));t.value.length<=n;)t.value.push(0);for(r=0;r<=n;r+=1)this.R[r]=909522486^t.value[r],this.U[r]=1549556828^t.value[r];this.m=this.g(this.R,this.m),this.A=this.T,this.p=!0}getHMAC(t,e){const n=a(e);return i(t,this.B,this.Y,n)(this.S())}S(){let t;if(!this.p)throw new Error("Cannot call getHMAC without first setting MAC key");const e=this.C(this.h.slice(),this.u,this.A,this.I(this.m),this.B);return t=this.g(this.U,this.L(this.o)),t=this.C(e,this.B,this.T,t,this.B),t}}{constructor(t,e,n){if("SHA-1"!==t)throw new Error("Chosen SHA variant is not supported");super(t,e,n);const r=n||{};this.M=!0,this.H=this.S,this.Y=-1,this.F=s(this.t,this.i,this.Y),this.g=d,this.I=function(t){return t.slice()},this.L=p,this.C=g,this.m=[1732584193,4023233417,2562383102,271733878,3285377520],this.T=512,this.B=160,this.v=!1,r.hmacKey&&this.N(function(t,e,n,r){const o="hmacKey must include a value and format";if(!e)throw new Error(o);if(void 0===e.value||!e.format)throw new Error(o);return s(e.format,e.encoding||"UTF8",n)(e.value)}(0,r.hmacKey,this.Y))}}},673:(t,e,n)=>{n.r(e),n.d(e,{default:()=>U});const r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function o(t,e,n,r){let o,s,i;const a=e||[0],u=(n=n||0)>>>3,h=-1===r?3:0;for(o=0;o<t.length;o+=1)i=o+u,s=i>>>2,a.length<=s&&a.push(0),a[s]|=t[o]<<8*(h+r*(i%4));return{value:a,binLen:8*t.length+n}}function s(t,e,n){switch(e){case"UTF8":case"UTF16BE":case"UTF16LE":break;default:throw new Error("encoding must be UTF8, UTF16BE, or UTF16LE")}switch(t){case"HEX":return function(t,e,r){return function(t,e,n,r){let o,s,i,a;if(0!=t.length%2)throw new Error("String of HEX type must be in byte increments");const u=e||[0],h=(n=n||0)>>>3,c=-1===r?3:0;for(o=0;o<t.length;o+=2){if(s=parseInt(t.substr(o,2),16),isNaN(s))throw new Error("String of HEX type contains invalid characters");for(a=(o>>>1)+h,i=a>>>2;u.length<=i;)u.push(0);u[i]|=s<<8*(c+r*(a%4))}return{value:u,binLen:4*t.length+n}}(t,e,r,n)};case"TEXT":return function(t,r,o){return function(t,e,n,r,o){let s,i,a,u,h,c,f,l,p=0;const d=n||[0],g=(r=r||0)>>>3;if("UTF8"===e)for(f=-1===o?3:0,a=0;a<t.length;a+=1)for(s=t.charCodeAt(a),i=[],128>s?i.push(s):2048>s?(i.push(192|s>>>6),i.push(128|63&s)):55296>s||57344<=s?i.push(224|s>>>12,128|s>>>6&63,128|63&s):(a+=1,s=65536+((1023&s)<<10|1023&t.charCodeAt(a)),i.push(240|s>>>18,128|s>>>12&63,128|s>>>6&63,128|63&s)),u=0;u<i.length;u+=1){for(c=p+g,h=c>>>2;d.length<=h;)d.push(0);d[h]|=i[u]<<8*(f+o*(c%4)),p+=1}else for(f=-1===o?2:0,l="UTF16LE"===e&&1!==o||"UTF16LE"!==e&&1===o,a=0;a<t.length;a+=1){for(s=t.charCodeAt(a),!0===l&&(u=255&s,s=u<<8|s>>>8),c=p+g,h=c>>>2;d.length<=h;)d.push(0);d[h]|=s<<8*(f+o*(c%4)),p+=2}return{value:d,binLen:8*p+r}}(t,e,r,o,n)};case"B64":return function(t,e,o){return function(t,e,n,o){let s,i,a,u,h,c,f,l=0;const p=e||[0],d=(n=n||0)>>>3,g=-1===o?3:0,y=t.indexOf("=");if(-1===t.search(/^[a-zA-Z0-9=+/]+$/))throw new Error("Invalid character in base-64 string");if(t=t.replace(/=/g,""),-1!==y&&y<t.length)throw new Error("Invalid '=' found in base-64 string");for(i=0;i<t.length;i+=4){for(h=t.substr(i,4),u=0,a=0;a<h.length;a+=1)s=r.indexOf(h.charAt(a)),u|=s<<18-6*a;for(a=0;a<h.length-1;a+=1){for(f=l+d,c=f>>>2;p.length<=c;)p.push(0);p[c]|=(u>>>16-8*a&255)<<8*(g+o*(f%4)),l+=1}}return{value:p,binLen:8*l+n}}(t,e,o,n)};case"BYTES":return function(t,e,r){return function(t,e,n,r){let o,s,i,a;const u=e||[0],h=(n=n||0)>>>3,c=-1===r?3:0;for(s=0;s<t.length;s+=1)o=t.charCodeAt(s),a=s+h,i=a>>>2,u.length<=i&&u.push(0),u[i]|=o<<8*(c+r*(a%4));return{value:u,binLen:8*t.length+n}}(t,e,r,n)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(t){throw new Error("ARRAYBUFFER not supported by this environment")}return function(t,e,r){return function(t,e,n,r){return o(new Uint8Array(t),e,n,r)}(t,e,r,n)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(t){throw new Error("UINT8ARRAY not supported by this environment")}return function(t,e,r){return o(t,e,r,n)};default:throw new Error("format must be HEX, TEXT, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}function i(t,e,n,o){switch(t){case"HEX":return function(t){return function(t,e,n,r){const o="0123456789abcdef";let s,i,a="";const u=e/8,h=-1===n?3:0;for(s=0;s<u;s+=1)i=t[s>>>2]>>>8*(h+n*(s%4)),a+=o.charAt(i>>>4&15)+o.charAt(15&i);return r.outputUpper?a.toUpperCase():a}(t,e,n,o)};case"B64":return function(t){return function(t,e,n,o){let s,i,a,u,h,c="";const f=e/8,l=-1===n?3:0;for(s=0;s<f;s+=3)for(u=s+1<f?t[s+1>>>2]:0,h=s+2<f?t[s+2>>>2]:0,a=(t[s>>>2]>>>8*(l+n*(s%4))&255)<<16|(u>>>8*(l+n*((s+1)%4))&255)<<8|h>>>8*(l+n*((s+2)%4))&255,i=0;i<4;i+=1)c+=8*s+6*i<=e?r.charAt(a>>>6*(3-i)&63):o.b64Pad;return c}(t,e,n,o)};case"BYTES":return function(t){return function(t,e,n){let r,o,s="";const i=e/8,a=-1===n?3:0;for(r=0;r<i;r+=1)o=t[r>>>2]>>>8*(a+n*(r%4))&255,s+=String.fromCharCode(o);return s}(t,e,n)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(t){throw new Error("ARRAYBUFFER not supported by this environment")}return function(t){return function(t,e,n){let r;const o=e/8,s=new ArrayBuffer(o),i=new Uint8Array(s),a=-1===n?3:0;for(r=0;r<o;r+=1)i[r]=t[r>>>2]>>>8*(a+n*(r%4))&255;return s}(t,e,n)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(t){throw new Error("UINT8ARRAY not supported by this environment")}return function(t){return function(t,e,n){let r;const o=e/8,s=-1===n?3:0,i=new Uint8Array(o);for(r=0;r<o;r+=1)i[r]=t[r>>>2]>>>8*(s+n*(r%4))&255;return i}(t,e,n)};default:throw new Error("format must be HEX, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}const a=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],u=[3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428],h=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225];function c(t){const e={outputUpper:!1,b64Pad:"=",outputLen:-1},n=t||{},r="Output length must be a multiple of 8";if(e.outputUpper=n.outputUpper||!1,n.b64Pad&&(e.b64Pad=n.b64Pad),n.outputLen){if(n.outputLen%8!=0)throw new Error(r);e.outputLen=n.outputLen}else if(n.shakeLen){if(n.shakeLen%8!=0)throw new Error(r);e.outputLen=n.shakeLen}if("boolean"!=typeof e.outputUpper)throw new Error("Invalid outputUpper formatting option");if("string"!=typeof e.b64Pad)throw new Error("Invalid b64Pad formatting option");return e}function f(t,e){return t>>>e|t<<32-e}function l(t,e){return t>>>e}function p(t,e,n){return t&e^~t&n}function d(t,e,n){return t&e^t&n^e&n}function g(t){return f(t,2)^f(t,13)^f(t,22)}function y(t,e){const n=(65535&t)+(65535&e);return(65535&(t>>>16)+(e>>>16)+(n>>>16))<<16|65535&n}function w(t,e,n,r){const o=(65535&t)+(65535&e)+(65535&n)+(65535&r);return(65535&(t>>>16)+(e>>>16)+(n>>>16)+(r>>>16)+(o>>>16))<<16|65535&o}function m(t,e,n,r,o){const s=(65535&t)+(65535&e)+(65535&n)+(65535&r)+(65535&o);return(65535&(t>>>16)+(e>>>16)+(n>>>16)+(r>>>16)+(o>>>16)+(s>>>16))<<16|65535&s}function b(t){return f(t,7)^f(t,18)^l(t,3)}function A(t){return f(t,6)^f(t,11)^f(t,25)}function v(t){let e;return e="SHA-224"==t?u.slice():h.slice(),e}function E(t,e){let n,r,o,s,i,u,h,c,v,E,U;const R=[];for(n=e[0],r=e[1],o=e[2],s=e[3],i=e[4],u=e[5],h=e[6],c=e[7],U=0;U<64;U+=1)R[U]=U<16?t[U]:w(f(S=R[U-2],17)^f(S,19)^l(S,10),R[U-7],b(R[U-15]),R[U-16]),v=m(c,A(i),p(i,u,h),a[U],R[U]),E=y(g(n),d(n,r,o)),c=h,h=u,u=i,i=y(s,v),s=o,o=r,r=n,n=y(v,E);var S;return e[0]=y(n,e[0]),e[1]=y(r,e[1]),e[2]=y(o,e[2]),e[3]=y(s,e[3]),e[4]=y(i,e[4]),e[5]=y(u,e[5]),e[6]=y(h,e[6]),e[7]=y(c,e[7]),e}class U extends class{constructor(t,e,n){const r=n||{};if(this.t=e,this.i=r.encoding||"UTF8",this.numRounds=r.numRounds||1,isNaN(this.numRounds)||this.numRounds!==parseInt(this.numRounds,10)||1>this.numRounds)throw new Error("numRounds must a integer >= 1");this.o=t,this.h=[],this.u=0,this.A=!1,this.l=0,this.p=!1,this.R=[],this.U=[]}update(t){let e,n=0;const r=this.T>>>5,o=this.F(t,this.h,this.u),s=o.binLen,i=o.value,a=s>>>5;for(e=0;e<a;e+=r)n+this.T<=s&&(this.m=this.g(i.slice(e,e+r),this.m),n+=this.T);return this.l+=n,this.h=i.slice(n>>>5),this.u=s%this.T,this.A=!0,this}getHash(t,e){let n,r,o=this.B;const s=c(e);if(this.H){if(-1===s.outputLen)throw new Error("Output length must be specified in options");o=s.outputLen}const a=i(t,o,this.v,s);if(this.p&&this.Y)return a(this.Y(s));for(r=this.C(this.h.slice(),this.u,this.l,this.S(this.m),o),n=1;n<this.numRounds;n+=1)this.H&&o%32!=0&&(r[r.length-1]&=16777215>>>24-o%32),r=this.C(r,o,0,this.I(this.o),o);return a(r)}setHMACKey(t,e,n){if(!this.L)throw new Error("Variant does not support HMAC");if(this.A)throw new Error("Cannot set MAC key after calling update");const r=s(e,(n||{}).encoding||"UTF8",this.v);this.M(r(t))}M(t){const e=this.T>>>3,n=e/4-1;let r;if(1!==this.numRounds)throw new Error("Cannot set numRounds with MAC");if(this.p)throw new Error("MAC key already set");for(e<t.binLen/8&&(t.value=this.C(t.value,t.binLen,0,this.I(this.o),this.B));t.value.length<=n;)t.value.push(0);for(r=0;r<=n;r+=1)this.R[r]=909522486^t.value[r],this.U[r]=1549556828^t.value[r];this.m=this.g(this.R,this.m),this.l=this.T,this.p=!0}getHMAC(t,e){const n=c(e);return i(t,this.B,this.v,n)(this.N())}N(){let t;if(!this.p)throw new Error("Cannot call getHMAC without first setting MAC key");const e=this.C(this.h.slice(),this.u,this.l,this.S(this.m),this.B);return t=this.g(this.U,this.I(this.o)),t=this.C(e,this.B,this.T,t,this.B),t}}{constructor(t,e,n){if("SHA-224"!==t&&"SHA-256"!==t)throw new Error("Chosen SHA variant is not supported");super(t,e,n);const r=n||{};this.Y=this.N,this.L=!0,this.v=-1,this.F=s(this.t,this.i,this.v),this.g=E,this.S=function(t){return t.slice()},this.I=v,this.C=function(e,n,r,o){return function(t,e,n,r,o){let s,i;const a=15+(e+65>>>9<<4),u=e+n;for(;t.length<=a;)t.push(0);for(t[e>>>5]|=128<<24-e%32,t[a]=4294967295&u,t[a-1]=u/4294967296|0,s=0;s<t.length;s+=16)r=E(t.slice(s,s+16),r);return i="SHA-224"===o?[r[0],r[1],r[2],r[3],r[4],r[5],r[6]]:r,i}(e,n,r,o,t)},this.m=v(t),this.T=512,this.B="SHA-224"===t?224:256,this.H=!1,r.hmacKey&&this.M(function(t,e,n,r){const o="hmacKey must include a value and format";if(!e)throw new Error(o);if(void 0===e.value||!e.format)throw new Error(o);return s(e.format,e.encoding||"UTF8",n)(e.value)}(0,r.hmacKey,this.v))}}}},e={};function n(r){var o=e[r];if(void 0!==o)return o.exports;var s=e[r]={exports:{}};return t[r](s,s.exports,n),s.exports}n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var r={};(()=>{n.d(r,{SO:()=>b(),Xz:()=>v,ul:()=>E,zM:()=>A,xI:()=>X,$$:()=>K,vB:()=>_,wY:()=>w,UQ:()=>p,Ue:()=>Z,w6:()=>y,Jx:()=>Y,cv:()=>R,Dd:()=>d,sK:()=>u,bX:()=>h,BO:()=>M,Dc:()=>f,fp:()=>l,xT:()=>g,Qc:()=>H,DN:()=>c,yQ:()=>T,Zk:()=>k,uh:()=>B});const t={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};let e;const o=new Uint8Array(16);function s(){if(!e&&(e="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!e))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return e(o)}const i=[];for(let t=0;t<256;++t)i.push((t+256).toString(16).slice(1));const a=function(e,n,r){if(t.randomUUID&&!n&&!e)return t.randomUUID();const o=(e=e||{}).random||(e.rng||s)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,n){r=r||0;for(let t=0;t<16;++t)n[r+t]=o[t];return n}return function(t,e=0){return(i[t[e+0]]+i[t[e+1]]+i[t[e+2]]+i[t[e+3]]+"-"+i[t[e+4]]+i[t[e+5]]+"-"+i[t[e+6]]+i[t[e+7]]+"-"+i[t[e+8]]+i[t[e+9]]+"-"+i[t[e+10]]+i[t[e+11]]+i[t[e+12]]+i[t[e+13]]+i[t[e+14]]+i[t[e+15]]).toLowerCase()}(o)};function u(t,e,n){let r=0,o=t.length;for(;r<o;){const s=r+o>>>1;n(t[s],e)<0?r=s+1:o=s}return r}function h(t,e){const n=[];for(const r of t)n.splice(u(n,r,e),0,r);return n}function c(t){let e=[];const n=new WeakMap;for(const r of t){const t=(r.webkitRelativePath||r.name).split("/");t.reduce(((e,o,s)=>{let i=e.find((t=>t[0]===o));if(i)return i[1];const a=u(e,o,((t,e)=>t[0]<e?-1:1));if(s===t.length-1){const t={"":{length:r.size}};n.set(t,r),i=[o,t]}else i=[o,[]];return e.splice(a,0,i),i[1]}),e)}let r;1===e.length&&Array.isArray(e[0][1])&&(r=e[0][0],e=e[0][1]);const o=[];return{fileTree:{*[Symbol.iterator](){for(const t of o)yield t},...function t(e){if(Array.isArray(e)){const n={};for(const r of e)n[r[0]]=t(r[1]);return n}{const t=e;return o.push(t),t}}(e)},fileNodeMap:n,commonDir:r}}async function f(t){const e=new Uint8Array(64);for(;t.length>1;){let n=!1;const r=[];for(const o of t)n?(e.set(o,32),r.push(new Uint8Array(await crypto.subtle.digest("SHA-256",e))),n=!1):(e.set(o),n=!0);t=r}return t[0]}function l(t){return 1<<32-Math.clz32(t-1)}function p(t){if(void 0===t)return;const e=[];for(const n of t)0!==n.length&&e.push(n);return 0!==e.length?e:void 0}function d(t){let e;for(const n of t){const t=(n.webkitRelativePath||n.name).split("/");if(1==t.length||(e??=t[0])!==t[0])return}return e}function g(t,e,n){const r=[],o=t.length-1;for(const[s,i]of t.entries()){if(r.push(i),s===o)break;const t=i.size%e;if(0===t)continue;const a=e-t,u=new File([new ArrayBuffer(a)],`${a}`,{type:"application/octet-stream"}),h=`.pad/${a}`,c=void 0===n?h:`${n}/${h}`;Object.defineProperties(u,{webkitRelativePath:{configurable:!0,enumerable:!0,get:()=>c},padding:{configurable:!0,enumerable:!1,get:()=>!0}}),r.push(u)}return r}function y(t,e,n){return void 0===e&&1===n.length?t=n[0].name:t??=e||a(),t}function w(t,e){return Math.max(e,l(t>>>10))}var m=n(340),b=n.n(m);const A=new Uint8Array([108]),v=new Uint8Array([100]),E=new Uint8Array([101]);class U{textEncoder=new TextEncoder;textDecoder=new TextDecoder;data;hooks;isHooking=!1;path=[];constructor(t,e){this.data=t,this.hooks=e}start(t){this.encode(this.data,t),t.close()}encode(t,e){if(null!=t)if("boolean"==typeof t)this.encode(t?1:0,e);else if("number"==typeof t){const n=Math.round(t);e.enqueue(this.textEncoder.encode(`i${n}e`)),n!==t&&(console.warn(`WARNING: Possible data corruption detected with value "${t}":`,`Bencoding only defines support for integers, value was converted to "${n}"`),console.trace())}else if("bigint"==typeof t)e.enqueue(this.textEncoder.encode(`i${t}e`));else if("string"==typeof t){const n=this.textEncoder.encode(t),r=n.byteLength;e.enqueue(this.textEncoder.encode(`${r}:`)),e.enqueue(n)}else if(t instanceof ArrayBuffer){const n=new Uint8Array(t),r=n.byteLength;e.enqueue(this.textEncoder.encode(`${r}:`)),e.enqueue(n)}else if(Array.isArray(t)){e.enqueue(A);for(let n of t)this.encode(n,e);e.enqueue(E)}else if(t instanceof Map){e.enqueue(v);const n=h(t.keys(),((t,e)=>(t="string"==typeof t?t:this.textDecoder.decode(t))<(e="string"==typeof e?e:this.textDecoder.decode(e))?-1:t>e?1:0));for(const r of n){const n=t.get(r);if(void 0!==n&&null!==t){if(this.path.push(r),this.encode(r,e),this.hooks){const t=this.hooks.get(this.path);if(t){const r=S(e,t);this.encode(n,r),t({value:void 0,done:!0})}else this.encode(n,e)}this.path.pop()}}e.enqueue(E)}else{e.enqueue(v);const n=Object.keys(t).sort();for(const r of n){const n=t[r];if(void 0!==n&&null!==t){if(this.path.push(r),this.encode(r,e),this.hooks){const t=this.hooks.get(this.path);if(t){const r=S(e,t);this.encode(n,r),t({value:void 0,done:!0})}else this.encode(n,e)}this.path.pop()}}e.enqueue(E)}}}function R(t,e){return new ReadableStream(new U(t,e))}function S(t,e){return new Proxy(t,{get:function(t,n,r){return"enqueue"!==n?Reflect.get(t,n,r):(n=>{t.enqueue(n),void 0!==n&&e({value:n,done:!1})}).bind(t)}})}function B(){const t={controller:null};return[new ReadableStream({start(e){t.controller=e}}),({value:e,done:n})=>{null!==t.controller&&(n?t.controller.close():t.controller.enqueue(e))}]}function T(){const[t,e]=B();return[new Response(t).arrayBuffer(),e]}function k(){const[t,e]=B();return[new Response(t).text(),e]}var L;!function(t){t.Integer="Integer",t.ByteString="ByteString",t.ListStart="ListStart",t.ListEnd="ListEnd",t.DictionaryStart="DictionaryStart",t.DictionaryEnd="DictionaryEnd"}(L||(L={}));const F=A[0],x=v[0],C=E[0];class I{endStack=[];token=null;byteStringLength=0;byteStringOffset=0;transform(t,e){this.tokenize(t,e)}flush(){if(this.endStack.length||this.token||this.byteStringLength||this.byteStringOffset)throw new SyntaxError("Incomplete stream")}tokenize(t,e){if(0!==t.byteLength)if(null===this.token&&0===this.byteStringLength){const n=t[0];if(105===n)this.token={type:L.Integer,value:new Uint8Array};else if(D(n))this.byteStringLength=n-48;else if(n===F)this.endStack.push(L.ListEnd),e.enqueue({type:L.ListStart});else if(n===x)this.endStack.push(L.DictionaryEnd),e.enqueue({type:L.DictionaryStart});else{if(n!==C)throw new SyntaxError(`Unexpected byte: ${n}`);{const t=this.endStack.pop();if(!t)throw new SyntaxError("Unbalanced delimiter");e.enqueue({type:t})}}this.tokenize(t.subarray(1),e)}else if(this.token&&0===this.byteStringLength)if(this.token.type===L.Integer){const n=t.indexOf(C);-1===n?this.token.value=this.token.value?z(this.token.value,t):t:(this.token.value=this.token.value?z(this.token.value,t.subarray(0,n)):t.subarray(0,n),e.enqueue(this.token),this.token=null,this.tokenize(t.subarray(n+1),e))}else{if(this.token.type!==L.ByteString)throw new Error("This is a bug");{const n=this.token.value.byteLength-this.byteStringOffset,r=t.byteLength;r<n?(this.token.value.set(t,this.byteStringOffset),this.byteStringOffset+=r):(this.token.value.set(t.subarray(0,n),this.byteStringOffset),this.byteStringOffset=0,e.enqueue(this.token),this.token=null,this.tokenize(t.subarray(n),e))}}else{if(!this.byteStringLength||null!==this.token)throw new Error("This is a bug");{let n=-1;for(const[e,r]of t.entries()){if(!D(r)){if(58===r){n=e;break}throw new SyntaxError(`Unexpected byte: ${r}`)}this.byteStringLength=10*this.byteStringLength-48+r}-1!==n&&(this.token={type:L.ByteString,value:new Uint8Array(this.byteStringLength)},this.byteStringLength=0,this.tokenize(t.subarray(n+1),e))}}}}function M(){return new TransformStream(new I)}async function H(t){let e;const n=[],r=t.getReader();let o;for(;;){const{done:t,value:s}=await r.read();if(t)break;const i=n.at(-1);if(i)if(Array.isArray(i))switch(s.type){case L.Integer:i.push(N(s.value));break;case L.ByteString:i.push(P(s.value));break;case L.DictionaryStart:{const t=Object.create(null);i.push(t),n.push(t);break}case L.ListStart:{const t=[];i.push(t),n.push(t);break}case L.ListEnd:n.pop();break;default:throw new SyntaxError(`Unexpected token: ${s}`)}else if(void 0===o)switch(s.type){case L.ByteString:o=P(s.value);break;case L.DictionaryEnd:n.pop();break;default:throw new SyntaxError(`Unexpected token: ${s}`)}else{switch(s.type){case L.Integer:i[o]=N(s.value);break;case L.ByteString:i[o]=P(s.value);break;case L.DictionaryStart:{const t=Object.create(null);i[o]=t,n.push(t);break}case L.ListStart:{const t=[];i[o]=t,n.push(t);break}default:throw new SyntaxError(`Unexpected token: ${s}`)}o=void 0}else{if(void 0!==e)throw new SyntaxError(`Unexpected token: ${s}`);switch(s.type){case L.Integer:e=N(s.value);break;case L.ByteString:e=P(s.value);break;case L.DictionaryStart:{const t=Object.create(null);n.push(t),e=t;break}case L.ListStart:{const t=[];n.push(t),e=t;break}default:throw new SyntaxError(`Unexpected token: ${s}`)}}}if(n.length)throw new Error("Unexpected end of token stream");return e}async function Y(t){const e=M(),n=t.pipeThrough(e);return await H(n)}function N(t){let e=0,n=!0;for(const[r,o]of t.entries()){if(0===r&&45===o){n=!1;continue}if(1===r&&!n&&48===o)throw new SyntaxError("Negative zero is not a valid integer");if(1===r&&0===e)throw new SyntaxError("Leading zeros are not allowed");if(!D(o))throw new SyntaxError(`Unexpected byte: ${o}`);const t=o-48;(n&&"number"==typeof e&&e>(Number.MAX_SAFE_INTEGER-t)/10||!n&&"number"==typeof e&&e<(Number.MIN_SAFE_INTEGER+t)/10)&&(e=BigInt(e)),e="number"==typeof e?n?10*e+t:10*e-t:n?10n*e+BigInt(t):10n*e-BigInt(t)}return e}function P(t){return(new TextDecoder).decode(t)}function D(t){return t>=48&&t<=57}function z(...t){const e=new Uint8Array(t.reduce(((t,e)=>t+e.byteLength),0));return t.reduce(((t,n)=>(e.set(n,t),t+n.byteLength)),0),e}n(913);class O extends Error{constructor(t,e){super(((t,...e)=>{let n=t;return e.length>0&&(n+=` :: ${JSON.stringify(e)}`),n})(t,e)),this.name=t,this.details=e}}class q{constructor(){this.promise=new Promise(((t,e)=>{this.resolve=t,this.reject=e}))}}function $(t){const e=t.map((t=>Promise.resolve(t).then((t=>function(t){if(t instanceof Response){if(t.body)return t.body.getReader();throw new O("opaque-streams-source",{type:t.type})}return t instanceof ReadableStream?t.getReader():new Response(t).body.getReader()}(t))))),n=new q;let r=0;const o=new ReadableStream({pull(t){return e[r].then((t=>t.read())).then((o=>{if(o.done)return r++,r>=e.length?(t.close(),void n.resolve()):this.pull(t);t.enqueue(o.value)})).catch((t=>{throw n.reject(t),t}))},cancel(){n.resolve()}});return{done:n.promise,stream:o}}var _;n(1),function(t){t.V1="v1",t.V2="v2",t.HYBRID="hybrid"}(_||(_={}));const K=16384;var X;!function(t){t[t["16KB"]=16384]="16KB",t[t["32KB"]=32768]="32KB",t[t["64KB"]=65536]="64KB",t[t["128KB"]=131072]="128KB",t[t["256KB"]=262144]="256KB",t[t["512KB"]=524288]="512KB",t[t["1MB"]=1048576]="1MB",t[t["2MB"]=2097152]="2MB",t[t["4MB"]=4194304]="4MB",t[t["8MB"]=8388608]="8MB",t[t["16MB"]=16777216]="16MB",t[t["32MB"]=33554432]="32MB"}(X||(X={}));const V=new Uint8Array(32),j={type:_.V1,addCreatedBy:!0,addCreationDate:!0,addPaddingFiles:!1,blockLength:K,sortFiles:!0,isPrivate:!1},Q={type:_.V2,addCreatedBy:!0,addCreationDate:!0,blockLength:K,metaVersion:2,isPrivate:!1},G={type:_.HYBRID,addCreatedBy:!0,addCreationDate:!0,blockLength:K,metaVersion:2,isPrivate:!1};async function Z(t,e={type:_.V1},r=((t,e)=>{})){if(0===t.length)throw new Error("empty file list");let o;switch(e.type){case _.V1:o={...j,...e};break;case _.V2:o={...Q,...e};break;case _.HYBRID:o={...G,...e}}o.pieceLength??=w(t.reduce(((t,e)=>t+e.size),0),o.blockLength);let{addCreatedBy:s,addCreationDate:i,blockLength:a,comment:u,isPrivate:h,name:m,pieceLength:b}=o;if(o.type!==_.V1&&b<a)throw new Error(`piece length ${b} is smaller than block length ${a}`);if(0!=(b&b-1))throw new Error(`piece length ${b} is not a power of 2`);const A=b/a;o.announceList=p(o.announceList),void 0===o.announce&&void 0!==o.announceList&&(o.announce=o.announceList[0][0]);const{announce:v,announceList:E}=o,U={...v&&{announce:v},...E&&{"announce-list":E},...u&&{comment:u},...s&&{"created by":"torrefy v2.0.2"},...i&&{"creation date":Date.now()/1e3>>0}};let R,S,B=0,T=t.reduce(((t,e)=>t+Math.ceil(e.size/b)),0);if(o.type===_.V1){const{addPaddingFiles:e,sortFiles:n}=o;let r,s;if(n){const{fileTree:e,fileNodeMap:n,commonDir:r}=c(t);t=[...e].map((t=>n.get(t))),s=r}else s=d(t);if(o.name=m=y(m,s,t),e){const e=t.length-1;r=$(t.map((async(t,n)=>L(t.stream(),{padding:n!==e})))).stream,t=g(t,b,s)}else{T=Math.ceil(t.reduce(((t,e)=>t+e.size),0)/b);const{stream:e}=$(t.map((t=>Promise.resolve(t.stream()))));r=L(e)}R={...U,info:{...t.length>1?{files:t.map((t=>{const e=(t.webkitRelativePath||t.name).split("/");return void 0!==s&&e.shift(),{...t.padding&&{attr:"p"},length:t.size,path:e}}))}:{length:t[0].size},name:m,"piece length":b,pieces:await new Response(r).arrayBuffer(),...h&&{private:1}}}}else if(o.type===_.V2){const{metaVersion:e}=o,{fileTree:n,fileNodeMap:r,commonDir:s}=c(t),i=[...n];t=i.map((t=>r.get(t)));const a=new Map;o.name=m=y(m,s,t),await Promise.all(i.map((async(e,n)=>{const r=t[n];await k(e,r,r.stream(),a)}))),R={...U,info:{"file tree":n,"meta version":e,name:m,"piece length":b,...h&&{private:1}},...a.size>0&&{"piece layers":a}}}else{if(o.type!==_.HYBRID)throw new Error("torrent type is not supported");{const{metaVersion:e}=o,{fileTree:n,fileNodeMap:r,commonDir:s}=c(t),i=[...n];t=i.map((t=>r.get(t)));const a=new Map;o.name=m=y(m,s,t),T*=2;const u=t.length-1,f=[];await Promise.all(i.map((async(e,n)=>{const r=t[n],[o,s]=r.stream().tee();f.push(Promise.resolve(L(o,{padding:n!==u}))),await k(e,r,s,a)})));const l=$(f).stream;t=g(t,b,s),R={...U,info:{"file tree":n,...t.length>1?{files:t.map((t=>{const e=(t.webkitRelativePath||t.name).split("/");return void 0!==s&&e.shift(),{...t.padding&&{attr:"p"},length:t.size,path:e}}))}:{length:t[0].size},"meta version":e,name:m,"piece length":b,pieces:await new Response(l).arrayBuffer(),...h&&{private:1}},...a.size>0&&{"piece layers":a}}}}return R;async function k(t,e,r,o){const[s,i]=function(t){const e=t.pipeThrough(F(a)).pipeThrough(function(){let t=0,e=[];return new TransformStream({transform:async(r,o)=>{let s;++t;try{s=new Uint8Array(await crypto.subtle.digest("SHA-256",r))}catch{const{default:t}=await Promise.resolve().then(n.bind(n,673)),e=new t("SHA-256","UINT8ARRAY");e.update(r),s=e.getHash("UINT8ARRAY")}e.push(s),e.length===A&&(o.enqueue(e),e=[])},flush:async n=>{if(0===t)return;let r=0;if(t<A)r=l(t)-t;else{const e=t%A;e>0&&(r=A-e)}if(r>0)for(let t=0;t<r;++t)e.push(V);e.length>0&&n.enqueue(e)}})}()).pipeThrough(x(!0)),[r,o]=e.tee();return[o.pipeThrough(C()).pipeThrough(x()),r]}(r),u=new Response(s).arrayBuffer();if(e.size>b){const t=new Response(i).arrayBuffer();o.set(await u,await t)}e.size>0&&(t[""]["pieces root"]=await u)}function L(t,e={padding:!1}){return t.pipeThrough(F(b,{padding:e.padding})).pipeThrough(function(t=!1){return new TransformStream({transform:async(e,o)=>{let s;try{s=new Uint8Array(await crypto.subtle.digest("SHA-1",e))}catch{const{default:t}=await Promise.resolve().then(n.bind(n,211)),r=new t("SHA-1","UINT8ARRAY");r.update(e),s=r.getHash("UINT8ARRAY")}o.enqueue(s),t&&r(++B,T)}})}(!0))}function F(t,e={padding:!1}){let n=new Uint8Array(t),r=0;return new TransformStream({transform:(e,o)=>{for(;r+e.length>=t;){const s=t-r;n.set(e.subarray(0,s),r),r=0,o.enqueue(new Uint8Array(n)),e=e.subarray(s)}n.set(e,r),r+=e.length},flush:o=>{r>0&&(e.padding?(n.set(new Uint8Array(t-r),r),o.enqueue(n)):o.enqueue(n.subarray(0,r)))}})}function x(t=!1){return new TransformStream({transform:async(e,n)=>{n.enqueue(await f(e)),t&&r(++B,T)}})}function C(){let t=0,e=[];return new TransformStream({transform:n=>{++t,e.push(n)},flush:async n=>{const r=l(t)-t;if(r>0){S??=await f(Array(A).fill(new Uint8Array(32)));for(let t=0;t<r;++t)e.push(S)}n.enqueue(e)}})}}})();var o=r.SO,s=r.Xz,i=r.ul,a=r.zM,u=r.xI,h=r.$$,c=r.vB,f=r.wY,l=r.UQ,p=r.Ue,d=r.w6,g=r.Jx,y=r.cv,w=r.Dd,m=r.sK,b=r.bX,A=r.BO,v=r.Dc,E=r.fp,U=r.xT,R=r.Qc,S=r.DN,B=r.yQ,T=r.Zk,k=r.uh;export{o as ArrayKeyedMap,s as BUFF_D,i as BUFF_E,a as BUFF_L,u as CommonPieceLength,h as DEFAULT_BLOCK_LENGTH,c as TorrentType,f as calculatePieceLength,l as collapseAnnounceList,p as create,d as decideName,g as decode,y as encode,w as getCommonDir,m as getSortedIndex,b as iterableSort,A as makeTokenizer,v as merkleRoot,E as nextPowerOfTwo,U as padFiles,R as parse,S as parseFileTree,B as useArrayBufferPromiseHook,T as useTextPromiseHook,k as useUint8ArrayStreamHook};
var e={913:()=>{try{self["workbox:core:6.5.3"]&&_()}catch(e){}},1:()=>{try{self["workbox:streams:6.5.3"]&&_()}catch(e){}},211:(e,t,n)=>{n.r(t),n.d(t,{default:()=>w});const r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function i(e,t,n,r){let i,s,o;const a=t||[0],u=(n=n||0)>>>3,c=-1===r?3:0;for(i=0;i<e.length;i+=1)o=i+u,s=o>>>2,a.length<=s&&a.push(0),a[s]|=e[i]<<8*(c+r*(o%4));return{value:a,binLen:8*e.length+n}}function s(e,t,n){switch(t){case"UTF8":case"UTF16BE":case"UTF16LE":break;default:throw new Error("encoding must be UTF8, UTF16BE, or UTF16LE")}switch(e){case"HEX":return function(e,t,r){return function(e,t,n,r){let i,s,o,a;if(0!=e.length%2)throw new Error("String of HEX type must be in byte increments");const u=t||[0],c=(n=n||0)>>>3,h=-1===r?3:0;for(i=0;i<e.length;i+=2){if(s=parseInt(e.substr(i,2),16),isNaN(s))throw new Error("String of HEX type contains invalid characters");for(a=(i>>>1)+c,o=a>>>2;u.length<=o;)u.push(0);u[o]|=s<<8*(h+r*(a%4))}return{value:u,binLen:4*e.length+n}}(e,t,r,n)};case"TEXT":return function(e,r,i){return function(e,t,n,r,i){let s,o,a,u,c,h,l,f,p=0;const d=n||[0],g=(r=r||0)>>>3;if("UTF8"===t)for(l=-1===i?3:0,a=0;a<e.length;a+=1)for(s=e.charCodeAt(a),o=[],128>s?o.push(s):2048>s?(o.push(192|s>>>6),o.push(128|63&s)):55296>s||57344<=s?o.push(224|s>>>12,128|s>>>6&63,128|63&s):(a+=1,s=65536+((1023&s)<<10|1023&e.charCodeAt(a)),o.push(240|s>>>18,128|s>>>12&63,128|s>>>6&63,128|63&s)),u=0;u<o.length;u+=1){for(h=p+g,c=h>>>2;d.length<=c;)d.push(0);d[c]|=o[u]<<8*(l+i*(h%4)),p+=1}else for(l=-1===i?2:0,f="UTF16LE"===t&&1!==i||"UTF16LE"!==t&&1===i,a=0;a<e.length;a+=1){for(s=e.charCodeAt(a),!0===f&&(u=255&s,s=u<<8|s>>>8),h=p+g,c=h>>>2;d.length<=c;)d.push(0);d[c]|=s<<8*(l+i*(h%4)),p+=2}return{value:d,binLen:8*p+r}}(e,t,r,i,n)};case"B64":return function(e,t,i){return function(e,t,n,i){let s,o,a,u,c,h,l,f=0;const p=t||[0],d=(n=n||0)>>>3,g=-1===i?3:0,w=e.indexOf("=");if(-1===e.search(/^[a-zA-Z0-9=+/]+$/))throw new Error("Invalid character in base-64 string");if(e=e.replace(/=/g,""),-1!==w&&w<e.length)throw new Error("Invalid '=' found in base-64 string");for(o=0;o<e.length;o+=4){for(c=e.substr(o,4),u=0,a=0;a<c.length;a+=1)s=r.indexOf(c.charAt(a)),u|=s<<18-6*a;for(a=0;a<c.length-1;a+=1){for(l=f+d,h=l>>>2;p.length<=h;)p.push(0);p[h]|=(u>>>16-8*a&255)<<8*(g+i*(l%4)),f+=1}}return{value:p,binLen:8*f+n}}(e,t,i,n)};case"BYTES":return function(e,t,r){return function(e,t,n,r){let i,s,o,a;const u=t||[0],c=(n=n||0)>>>3,h=-1===r?3:0;for(s=0;s<e.length;s+=1)i=e.charCodeAt(s),a=s+c,o=a>>>2,u.length<=o&&u.push(0),u[o]|=i<<8*(h+r*(a%4));return{value:u,binLen:8*e.length+n}}(e,t,r,n)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(e){throw new Error("ARRAYBUFFER not supported by this environment")}return function(e,t,r){return function(e,t,n,r){return i(new Uint8Array(e),t,n,r)}(e,t,r,n)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(e){throw new Error("UINT8ARRAY not supported by this environment")}return function(e,t,r){return i(e,t,r,n)};default:throw new Error("format must be HEX, TEXT, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}function o(e,t,n,i){switch(e){case"HEX":return function(e){return function(e,t,n,r){const i="0123456789abcdef";let s,o,a="";const u=t/8,c=-1===n?3:0;for(s=0;s<u;s+=1)o=e[s>>>2]>>>8*(c+n*(s%4)),a+=i.charAt(o>>>4&15)+i.charAt(15&o);return r.outputUpper?a.toUpperCase():a}(e,t,n,i)};case"B64":return function(e){return function(e,t,n,i){let s,o,a,u,c,h="";const l=t/8,f=-1===n?3:0;for(s=0;s<l;s+=3)for(u=s+1<l?e[s+1>>>2]:0,c=s+2<l?e[s+2>>>2]:0,a=(e[s>>>2]>>>8*(f+n*(s%4))&255)<<16|(u>>>8*(f+n*((s+1)%4))&255)<<8|c>>>8*(f+n*((s+2)%4))&255,o=0;o<4;o+=1)h+=8*s+6*o<=t?r.charAt(a>>>6*(3-o)&63):i.b64Pad;return h}(e,t,n,i)};case"BYTES":return function(e){return function(e,t,n){let r,i,s="";const o=t/8,a=-1===n?3:0;for(r=0;r<o;r+=1)i=e[r>>>2]>>>8*(a+n*(r%4))&255,s+=String.fromCharCode(i);return s}(e,t,n)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(e){throw new Error("ARRAYBUFFER not supported by this environment")}return function(e){return function(e,t,n){let r;const i=t/8,s=new ArrayBuffer(i),o=new Uint8Array(s),a=-1===n?3:0;for(r=0;r<i;r+=1)o[r]=e[r>>>2]>>>8*(a+n*(r%4))&255;return s}(e,t,n)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(e){throw new Error("UINT8ARRAY not supported by this environment")}return function(e){return function(e,t,n){let r;const i=t/8,s=-1===n?3:0,o=new Uint8Array(i);for(r=0;r<i;r+=1)o[r]=e[r>>>2]>>>8*(s+n*(r%4))&255;return o}(e,t,n)};default:throw new Error("format must be HEX, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}function a(e){const t={outputUpper:!1,b64Pad:"=",outputLen:-1},n=e||{},r="Output length must be a multiple of 8";if(t.outputUpper=n.outputUpper||!1,n.b64Pad&&(t.b64Pad=n.b64Pad),n.outputLen){if(n.outputLen%8!=0)throw new Error(r);t.outputLen=n.outputLen}else if(n.shakeLen){if(n.shakeLen%8!=0)throw new Error(r);t.outputLen=n.shakeLen}if("boolean"!=typeof t.outputUpper)throw new Error("Invalid outputUpper formatting option");if("string"!=typeof t.b64Pad)throw new Error("Invalid b64Pad formatting option");return t}function u(e,t){return e<<t|e>>>32-t}function c(e,t,n){return e^t^n}function h(e,t,n){return e&t^e&n^t&n}function l(e,t){const n=(65535&e)+(65535&t);return(65535&(e>>>16)+(t>>>16)+(n>>>16))<<16|65535&n}function f(e,t,n,r,i){const s=(65535&e)+(65535&t)+(65535&n)+(65535&r)+(65535&i);return(65535&(e>>>16)+(t>>>16)+(n>>>16)+(r>>>16)+(i>>>16)+(s>>>16))<<16|65535&s}function p(e){return[1732584193,4023233417,2562383102,271733878,3285377520]}function d(e,t){let n,r,i,s,o,a,p;const d=[];for(n=t[0],r=t[1],i=t[2],s=t[3],o=t[4],p=0;p<80;p+=1)d[p]=p<16?e[p]:u(d[p-3]^d[p-8]^d[p-14]^d[p-16],1),a=p<20?f(u(n,5),(g=r)&i^~g&s,o,1518500249,d[p]):p<40?f(u(n,5),c(r,i,s),o,1859775393,d[p]):p<60?f(u(n,5),h(r,i,s),o,2400959708,d[p]):f(u(n,5),c(r,i,s),o,3395469782,d[p]),o=s,s=i,i=u(r,30),r=n,n=a;var g;return t[0]=l(n,t[0]),t[1]=l(r,t[1]),t[2]=l(i,t[2]),t[3]=l(s,t[3]),t[4]=l(o,t[4]),t}function g(e,t,n,r){let i;const s=15+(t+65>>>9<<4),o=t+n;for(;e.length<=s;)e.push(0);for(e[t>>>5]|=128<<24-t%32,e[s]=4294967295&o,e[s-1]=o/4294967296|0,i=0;i<e.length;i+=16)r=d(e.slice(i,i+16),r);return r}class w extends class{constructor(e,t,n){const r=n||{};if(this.t=t,this.i=r.encoding||"UTF8",this.numRounds=r.numRounds||1,isNaN(this.numRounds)||this.numRounds!==parseInt(this.numRounds,10)||1>this.numRounds)throw new Error("numRounds must a integer >= 1");this.o=e,this.h=[],this.u=0,this.l=!1,this.A=0,this.p=!1,this.R=[],this.U=[]}update(e){let t,n=0;const r=this.T>>>5,i=this.F(e,this.h,this.u),s=i.binLen,o=i.value,a=s>>>5;for(t=0;t<a;t+=r)n+this.T<=s&&(this.m=this.g(o.slice(t,t+r),this.m),n+=this.T);return this.A+=n,this.h=o.slice(n>>>5),this.u=s%this.T,this.l=!0,this}getHash(e,t){let n,r,i=this.B;const s=a(t);if(this.v){if(-1===s.outputLen)throw new Error("Output length must be specified in options");i=s.outputLen}const u=o(e,i,this.Y,s);if(this.p&&this.H)return u(this.H(s));for(r=this.C(this.h.slice(),this.u,this.A,this.I(this.m),i),n=1;n<this.numRounds;n+=1)this.v&&i%32!=0&&(r[r.length-1]&=16777215>>>24-i%32),r=this.C(r,i,0,this.L(this.o),i);return u(r)}setHMACKey(e,t,n){if(!this.M)throw new Error("Variant does not support HMAC");if(this.l)throw new Error("Cannot set MAC key after calling update");const r=s(t,(n||{}).encoding||"UTF8",this.Y);this.N(r(e))}N(e){const t=this.T>>>3,n=t/4-1;let r;if(1!==this.numRounds)throw new Error("Cannot set numRounds with MAC");if(this.p)throw new Error("MAC key already set");for(t<e.binLen/8&&(e.value=this.C(e.value,e.binLen,0,this.L(this.o),this.B));e.value.length<=n;)e.value.push(0);for(r=0;r<=n;r+=1)this.R[r]=909522486^e.value[r],this.U[r]=1549556828^e.value[r];this.m=this.g(this.R,this.m),this.A=this.T,this.p=!0}getHMAC(e,t){const n=a(t);return o(e,this.B,this.Y,n)(this.S())}S(){let e;if(!this.p)throw new Error("Cannot call getHMAC without first setting MAC key");const t=this.C(this.h.slice(),this.u,this.A,this.I(this.m),this.B);return e=this.g(this.U,this.L(this.o)),e=this.C(t,this.B,this.T,e,this.B),e}}{constructor(e,t,n){if("SHA-1"!==e)throw new Error("Chosen SHA variant is not supported");super(e,t,n);const r=n||{};this.M=!0,this.H=this.S,this.Y=-1,this.F=s(this.t,this.i,this.Y),this.g=d,this.I=function(e){return e.slice()},this.L=p,this.C=g,this.m=[1732584193,4023233417,2562383102,271733878,3285377520],this.T=512,this.B=160,this.v=!1,r.hmacKey&&this.N(function(e,t,n,r){const i="hmacKey must include a value and format";if(!t)throw new Error(i);if(void 0===t.value||!t.format)throw new Error(i);return s(t.format,t.encoding||"UTF8",n)(t.value)}(0,r.hmacKey,this.Y))}}},673:(e,t,n)=>{n.r(t),n.d(t,{default:()=>A});const r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function i(e,t,n,r){let i,s,o;const a=t||[0],u=(n=n||0)>>>3,c=-1===r?3:0;for(i=0;i<e.length;i+=1)o=i+u,s=o>>>2,a.length<=s&&a.push(0),a[s]|=e[i]<<8*(c+r*(o%4));return{value:a,binLen:8*e.length+n}}function s(e,t,n){switch(t){case"UTF8":case"UTF16BE":case"UTF16LE":break;default:throw new Error("encoding must be UTF8, UTF16BE, or UTF16LE")}switch(e){case"HEX":return function(e,t,r){return function(e,t,n,r){let i,s,o,a;if(0!=e.length%2)throw new Error("String of HEX type must be in byte increments");const u=t||[0],c=(n=n||0)>>>3,h=-1===r?3:0;for(i=0;i<e.length;i+=2){if(s=parseInt(e.substr(i,2),16),isNaN(s))throw new Error("String of HEX type contains invalid characters");for(a=(i>>>1)+c,o=a>>>2;u.length<=o;)u.push(0);u[o]|=s<<8*(h+r*(a%4))}return{value:u,binLen:4*e.length+n}}(e,t,r,n)};case"TEXT":return function(e,r,i){return function(e,t,n,r,i){let s,o,a,u,c,h,l,f,p=0;const d=n||[0],g=(r=r||0)>>>3;if("UTF8"===t)for(l=-1===i?3:0,a=0;a<e.length;a+=1)for(s=e.charCodeAt(a),o=[],128>s?o.push(s):2048>s?(o.push(192|s>>>6),o.push(128|63&s)):55296>s||57344<=s?o.push(224|s>>>12,128|s>>>6&63,128|63&s):(a+=1,s=65536+((1023&s)<<10|1023&e.charCodeAt(a)),o.push(240|s>>>18,128|s>>>12&63,128|s>>>6&63,128|63&s)),u=0;u<o.length;u+=1){for(h=p+g,c=h>>>2;d.length<=c;)d.push(0);d[c]|=o[u]<<8*(l+i*(h%4)),p+=1}else for(l=-1===i?2:0,f="UTF16LE"===t&&1!==i||"UTF16LE"!==t&&1===i,a=0;a<e.length;a+=1){for(s=e.charCodeAt(a),!0===f&&(u=255&s,s=u<<8|s>>>8),h=p+g,c=h>>>2;d.length<=c;)d.push(0);d[c]|=s<<8*(l+i*(h%4)),p+=2}return{value:d,binLen:8*p+r}}(e,t,r,i,n)};case"B64":return function(e,t,i){return function(e,t,n,i){let s,o,a,u,c,h,l,f=0;const p=t||[0],d=(n=n||0)>>>3,g=-1===i?3:0,w=e.indexOf("=");if(-1===e.search(/^[a-zA-Z0-9=+/]+$/))throw new Error("Invalid character in base-64 string");if(e=e.replace(/=/g,""),-1!==w&&w<e.length)throw new Error("Invalid '=' found in base-64 string");for(o=0;o<e.length;o+=4){for(c=e.substr(o,4),u=0,a=0;a<c.length;a+=1)s=r.indexOf(c.charAt(a)),u|=s<<18-6*a;for(a=0;a<c.length-1;a+=1){for(l=f+d,h=l>>>2;p.length<=h;)p.push(0);p[h]|=(u>>>16-8*a&255)<<8*(g+i*(l%4)),f+=1}}return{value:p,binLen:8*f+n}}(e,t,i,n)};case"BYTES":return function(e,t,r){return function(e,t,n,r){let i,s,o,a;const u=t||[0],c=(n=n||0)>>>3,h=-1===r?3:0;for(s=0;s<e.length;s+=1)i=e.charCodeAt(s),a=s+c,o=a>>>2,u.length<=o&&u.push(0),u[o]|=i<<8*(h+r*(a%4));return{value:u,binLen:8*e.length+n}}(e,t,r,n)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(e){throw new Error("ARRAYBUFFER not supported by this environment")}return function(e,t,r){return function(e,t,n,r){return i(new Uint8Array(e),t,n,r)}(e,t,r,n)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(e){throw new Error("UINT8ARRAY not supported by this environment")}return function(e,t,r){return i(e,t,r,n)};default:throw new Error("format must be HEX, TEXT, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}function o(e,t,n,i){switch(e){case"HEX":return function(e){return function(e,t,n,r){const i="0123456789abcdef";let s,o,a="";const u=t/8,c=-1===n?3:0;for(s=0;s<u;s+=1)o=e[s>>>2]>>>8*(c+n*(s%4)),a+=i.charAt(o>>>4&15)+i.charAt(15&o);return r.outputUpper?a.toUpperCase():a}(e,t,n,i)};case"B64":return function(e){return function(e,t,n,i){let s,o,a,u,c,h="";const l=t/8,f=-1===n?3:0;for(s=0;s<l;s+=3)for(u=s+1<l?e[s+1>>>2]:0,c=s+2<l?e[s+2>>>2]:0,a=(e[s>>>2]>>>8*(f+n*(s%4))&255)<<16|(u>>>8*(f+n*((s+1)%4))&255)<<8|c>>>8*(f+n*((s+2)%4))&255,o=0;o<4;o+=1)h+=8*s+6*o<=t?r.charAt(a>>>6*(3-o)&63):i.b64Pad;return h}(e,t,n,i)};case"BYTES":return function(e){return function(e,t,n){let r,i,s="";const o=t/8,a=-1===n?3:0;for(r=0;r<o;r+=1)i=e[r>>>2]>>>8*(a+n*(r%4))&255,s+=String.fromCharCode(i);return s}(e,t,n)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(e){throw new Error("ARRAYBUFFER not supported by this environment")}return function(e){return function(e,t,n){let r;const i=t/8,s=new ArrayBuffer(i),o=new Uint8Array(s),a=-1===n?3:0;for(r=0;r<i;r+=1)o[r]=e[r>>>2]>>>8*(a+n*(r%4))&255;return s}(e,t,n)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(e){throw new Error("UINT8ARRAY not supported by this environment")}return function(e){return function(e,t,n){let r;const i=t/8,s=-1===n?3:0,o=new Uint8Array(i);for(r=0;r<i;r+=1)o[r]=e[r>>>2]>>>8*(s+n*(r%4))&255;return o}(e,t,n)};default:throw new Error("format must be HEX, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}const a=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],u=[3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428],c=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225];function h(e){const t={outputUpper:!1,b64Pad:"=",outputLen:-1},n=e||{},r="Output length must be a multiple of 8";if(t.outputUpper=n.outputUpper||!1,n.b64Pad&&(t.b64Pad=n.b64Pad),n.outputLen){if(n.outputLen%8!=0)throw new Error(r);t.outputLen=n.outputLen}else if(n.shakeLen){if(n.shakeLen%8!=0)throw new Error(r);t.outputLen=n.shakeLen}if("boolean"!=typeof t.outputUpper)throw new Error("Invalid outputUpper formatting option");if("string"!=typeof t.b64Pad)throw new Error("Invalid b64Pad formatting option");return t}function l(e,t){return e>>>t|e<<32-t}function f(e,t){return e>>>t}function p(e,t,n){return e&t^~e&n}function d(e,t,n){return e&t^e&n^t&n}function g(e){return l(e,2)^l(e,13)^l(e,22)}function w(e,t){const n=(65535&e)+(65535&t);return(65535&(e>>>16)+(t>>>16)+(n>>>16))<<16|65535&n}function y(e,t,n,r){const i=(65535&e)+(65535&t)+(65535&n)+(65535&r);return(65535&(e>>>16)+(t>>>16)+(n>>>16)+(r>>>16)+(i>>>16))<<16|65535&i}function m(e,t,n,r,i){const s=(65535&e)+(65535&t)+(65535&n)+(65535&r)+(65535&i);return(65535&(e>>>16)+(t>>>16)+(n>>>16)+(r>>>16)+(i>>>16)+(s>>>16))<<16|65535&s}function b(e){return l(e,7)^l(e,18)^f(e,3)}function v(e){return l(e,6)^l(e,11)^l(e,25)}function L(e){let t;return t="SHA-224"==e?u.slice():c.slice(),t}function k(e,t){let n,r,i,s,o,u,c,h,L,k,A;const E=[];for(n=t[0],r=t[1],i=t[2],s=t[3],o=t[4],u=t[5],c=t[6],h=t[7],A=0;A<64;A+=1)E[A]=A<16?e[A]:y(l(R=E[A-2],17)^l(R,19)^f(R,10),E[A-7],b(E[A-15]),E[A-16]),L=m(h,v(o),p(o,u,c),a[A],E[A]),k=w(g(n),d(n,r,i)),h=c,c=u,u=o,o=w(s,L),s=i,i=r,r=n,n=w(L,k);var R;return t[0]=w(n,t[0]),t[1]=w(r,t[1]),t[2]=w(i,t[2]),t[3]=w(s,t[3]),t[4]=w(o,t[4]),t[5]=w(u,t[5]),t[6]=w(c,t[6]),t[7]=w(h,t[7]),t}class A extends class{constructor(e,t,n){const r=n||{};if(this.t=t,this.i=r.encoding||"UTF8",this.numRounds=r.numRounds||1,isNaN(this.numRounds)||this.numRounds!==parseInt(this.numRounds,10)||1>this.numRounds)throw new Error("numRounds must a integer >= 1");this.o=e,this.h=[],this.u=0,this.A=!1,this.l=0,this.p=!1,this.R=[],this.U=[]}update(e){let t,n=0;const r=this.T>>>5,i=this.F(e,this.h,this.u),s=i.binLen,o=i.value,a=s>>>5;for(t=0;t<a;t+=r)n+this.T<=s&&(this.m=this.g(o.slice(t,t+r),this.m),n+=this.T);return this.l+=n,this.h=o.slice(n>>>5),this.u=s%this.T,this.A=!0,this}getHash(e,t){let n,r,i=this.B;const s=h(t);if(this.H){if(-1===s.outputLen)throw new Error("Output length must be specified in options");i=s.outputLen}const a=o(e,i,this.v,s);if(this.p&&this.Y)return a(this.Y(s));for(r=this.C(this.h.slice(),this.u,this.l,this.S(this.m),i),n=1;n<this.numRounds;n+=1)this.H&&i%32!=0&&(r[r.length-1]&=16777215>>>24-i%32),r=this.C(r,i,0,this.I(this.o),i);return a(r)}setHMACKey(e,t,n){if(!this.L)throw new Error("Variant does not support HMAC");if(this.A)throw new Error("Cannot set MAC key after calling update");const r=s(t,(n||{}).encoding||"UTF8",this.v);this.M(r(e))}M(e){const t=this.T>>>3,n=t/4-1;let r;if(1!==this.numRounds)throw new Error("Cannot set numRounds with MAC");if(this.p)throw new Error("MAC key already set");for(t<e.binLen/8&&(e.value=this.C(e.value,e.binLen,0,this.I(this.o),this.B));e.value.length<=n;)e.value.push(0);for(r=0;r<=n;r+=1)this.R[r]=909522486^e.value[r],this.U[r]=1549556828^e.value[r];this.m=this.g(this.R,this.m),this.l=this.T,this.p=!0}getHMAC(e,t){const n=h(t);return o(e,this.B,this.v,n)(this.N())}N(){let e;if(!this.p)throw new Error("Cannot call getHMAC without first setting MAC key");const t=this.C(this.h.slice(),this.u,this.l,this.S(this.m),this.B);return e=this.g(this.U,this.I(this.o)),e=this.C(t,this.B,this.T,e,this.B),e}}{constructor(e,t,n){if("SHA-224"!==e&&"SHA-256"!==e)throw new Error("Chosen SHA variant is not supported");super(e,t,n);const r=n||{};this.Y=this.N,this.L=!0,this.v=-1,this.F=s(this.t,this.i,this.v),this.g=k,this.S=function(e){return e.slice()},this.I=L,this.C=function(t,n,r,i){return function(e,t,n,r,i){let s,o;const a=15+(t+65>>>9<<4),u=t+n;for(;e.length<=a;)e.push(0);for(e[t>>>5]|=128<<24-t%32,e[a]=4294967295&u,e[a-1]=u/4294967296|0,s=0;s<e.length;s+=16)r=k(e.slice(s,s+16),r);return o="SHA-224"===i?[r[0],r[1],r[2],r[3],r[4],r[5],r[6]]:r,o}(t,n,r,i,e)},this.m=L(e),this.T=512,this.B="SHA-224"===e?224:256,this.H=!1,r.hmacKey&&this.M(function(e,t,n,r){const i="hmacKey must include a value and format";if(!t)throw new Error(i);if(void 0===t.value||!t.format)throw new Error(i);return s(t.format,t.encoding||"UTF8",n)(t.value)}(0,r.hmacKey,this.v))}}}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var s=t[r]={exports:{}};return e[r](s,s.exports,n),s.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};(()=>{n.d(r,{j$:()=>g,nm:()=>l,Xz:()=>s,ul:()=>a,zo:()=>c,zM:()=>t,pI:()=>p,I4:()=>d,Fl:()=>h,In:()=>i,Cj:()=>o,t6:()=>u,mh:()=>e,LQ:()=>f,R2:()=>z,rJ:()=>q,xI:()=>Le,$$:()=>ve,e9:()=>X,K2:()=>j,ZC:()=>J,iv:()=>B,d2:()=>F,vB:()=>be,y1:()=>me,Hv:()=>b,Ue:()=>Ue,Jx:()=>x,cv:()=>E,Pi:()=>ne,um:()=>re,sK:()=>y,Fw:()=>w,zE:()=>W,RU:()=>Z,Xs:()=>G,r1:()=>Q,Kl:()=>ee,A7:()=>ye,px:()=>ge,ZW:()=>we,ti:()=>de,bX:()=>m,Dc:()=>L,fp:()=>v,Ye:()=>fe,Qc:()=>C,hP:()=>le,LU:()=>he,yQ:()=>S,Zk:()=>T,uh:()=>U});const e=108,t=new Uint8Array([e]),i=100,s=new Uint8Array([i]),o=101,a=new Uint8Array([o]),u=105,c=new Uint8Array([u]),h=58,l=new Uint8Array([h]),f=45,p=new Uint8Array([f]),d=48,g=new Uint8Array([d]);function w(e){return e>=d&&e<=d+9}function y(e,t,n){let r=0,i=e.length;for(;r<i;){const s=r+i>>>1,o=n(e[s],t);if(0===o)return{index:s,result:e[s]};o<0?r=s+1:i=s}return{index:r,result:void 0}}function m(e,t){const n=[];for(const r of e){const{index:e}=y(n,r,t);n.splice(e,0,r)}return n}function b(...e){const t=new Uint8Array(e.reduce(((e,t)=>e+t.byteLength),0));return e.reduce(((e,n)=>(t.set(n,e),e+n.byteLength)),0),t}function v(e){return 1<<32-Math.clz32(e-1)}async function L(e){if(0===e.length)throw new Error("Empty leaves");const t=new Uint8Array(64);for(;e.length>1;){let r=!1;const i=[];for(const s of e)if(r){let e;t.set(s,32);try{e=new Uint8Array(await crypto.subtle.digest("SHA-256",t))}catch{const{default:r}=await Promise.resolve().then(n.bind(n,673)),i=new r("SHA-256","UINT8ARRAY");i.update(t),e=i.getHash("UINT8ARRAY")}i.push(e),r=!1}else t.set(s),r=!0;e=i}return e[0]}const k=new WeakMap;class A{textEncoder=new TextEncoder;textDecoder=new TextDecoder;data;path=[];hooks;consumedHookHandler=new WeakMap;constructor(e,t){this.data=e,this.hooks=t,t&&k.set(t,!0)}start(e){if(this.encode(this.data,e),this.hooks)for(const e of this.hooks.values())this.consumedHookHandler.get(e)||e({value:void 0,done:!0});e.close()}encode(e,n){if(null!=e)if("boolean"==typeof e)this.encode(e?1:0,n);else if("number"==typeof e){const t=Math.round(e);n.enqueue(this.textEncoder.encode(`i${t}e`)),t!==e&&(console.warn(`WARNING: Possible data corruption detected with value "${e}":`,`Bencoding only defines support for integers, value was converted to "${t}"`),console.trace())}else if("bigint"==typeof e)n.enqueue(this.textEncoder.encode(`i${e}e`));else if("string"==typeof e){const t=this.textEncoder.encode(e),r=t.byteLength;n.enqueue(this.textEncoder.encode(`${r}:`)),n.enqueue(t)}else if(e instanceof ArrayBuffer){const t=new Uint8Array(e),r=t.byteLength;n.enqueue(this.textEncoder.encode(`${r}:`)),n.enqueue(t)}else if(Array.isArray(e)){n.enqueue(t);let r=0;for(const t of e){if(this.path.push(r),this.hooks){const e=this.hooks.get(this.path);if(e){const r=R(n,e);this.encode(t,r),e({value:void 0,done:!0})}else this.encode(t,n)}this.path.pop(),++r}n.enqueue(a)}else if(e instanceof Map){n.enqueue(s);const t=m(e.keys(),((e,t)=>(e="string"==typeof e?e:this.textDecoder.decode(e))<(t="string"==typeof t?t:this.textDecoder.decode(t))?-1:e>t?1:0));for(const r of t){const t=e.get(r);if(void 0!==t&&null!==e)if(r instanceof ArrayBuffer)this.encode(r,n),this.encode(t,n);else{if(this.path.push(r),this.encode(r,n),this.hooks){const e=this.hooks.get(this.path);if(e){const r=R(n,e);this.encode(t,r),e({value:void 0,done:!0}),this.consumedHookHandler.set(e,!0)}else this.encode(t,n)}this.path.pop()}}n.enqueue(a)}else{n.enqueue(s);const t=Object.keys(e).sort();for(const r of t){const t=e[r];if(void 0!==t&&null!==e){if(this.path.push(r),this.encode(r,n),this.hooks){const e=this.hooks.get(this.path);if(e){const r=R(n,e);this.encode(t,r),e({value:void 0,done:!0}),this.consumedHookHandler.set(e,!0)}else this.encode(t,n)}this.path.pop()}}n.enqueue(a)}}}function E(e,t){return new ReadableStream(new A(e,t))}function R(e,t){return new Proxy(e,{get:function(e,n,r){return"enqueue"===n?(n=>{e.enqueue(n),t({value:n,done:!1})}).bind(e):Reflect.get(e,n,r)}})}function U(e,t){const n={controller:null},r=new ReadableStream({start(e){n.controller=e},pull(e){k.get(t)||(console.warn("You need to call encode() first and then consume hooks."),e.close(),n.controller=null)}});return t.set(e,(({value:e,done:t})=>{null!==n.controller&&(t?n.controller.close():n.controller.enqueue(e))})),[r]}function S(e,t){const[n]=U(e,t);return[new Response(n).arrayBuffer()]}function T(e,t){const[n]=U(e,t);return[new Response(n).text()]}var B;!function(e){e.Integer="Integer",e.ByteString="ByteString",e.ListStart="ListStart",e.ListEnd="ListEnd",e.DictionaryStart="DictionaryStart",e.DictionaryEnd="DictionaryEnd",e.NewTokenType="NewTokenType"}(B||(B={}));class P{endStack=[];token=null;byteStringLength=-1;byteStringOffset=0;transform(e,t){this.tokenize(e,t)}flush(){if(this.endStack.length||this.token||-1!==this.byteStringLength||this.byteStringOffset)throw new SyntaxError("Unexpected end of torrent stream")}tokenize(t,n){if(0!==t.byteLength)if(null===this.token&&-1===this.byteStringLength){const r=t[0];if(r===u)this.token={type:B.Integer,value:new Uint8Array};else if(w(r))this.byteStringLength=r-d;else if(r===e)this.endStack.push(B.ListEnd),n.enqueue({type:B.ListStart});else if(r===i)this.endStack.push(B.DictionaryEnd),n.enqueue({type:B.DictionaryStart});else{if(r!==o)throw new SyntaxError(`Unexpected byte: ${r}`);{const e=this.endStack.pop();if(!e)throw new SyntaxError("Unbalanced delimiter");n.enqueue({type:e})}}this.tokenize(t.subarray(1),n)}else if(this.token&&-1===this.byteStringLength)if(this.token.type===B.Integer){const e=t.indexOf(o);-1===e?this.token.value=this.token.value?b(this.token.value,t):t:(this.token.value=this.token.value?b(this.token.value,t.subarray(0,e)):t.subarray(0,e),n.enqueue(this.token),this.token=null,this.tokenize(t.subarray(e+1),n))}else{if(this.token.type!==B.ByteString)throw new Error("This is a bug");{const e=this.token.value.byteLength-this.byteStringOffset,r=t.byteLength;r<e?(this.token.value.set(t,this.byteStringOffset),this.byteStringOffset+=r):(this.token.value.set(t.subarray(0,e),this.byteStringOffset),this.byteStringOffset=0,n.enqueue(this.token),this.token=null,this.tokenize(t.subarray(e),n))}}else{if(!(this.byteStringLength>-1&&null===this.token))throw new Error("This is a bug");{let e=-1;for(const[n,r]of t.entries()){if(!w(r)){if(r===h){e=n;break}throw new SyntaxError(`Unexpected byte: ${r}`)}this.byteStringLength=10*this.byteStringLength-d+r}-1!==e&&(this.token={type:B.ByteString,value:new Uint8Array(this.byteStringLength)},this.byteStringLength=-1,this.tokenize(t.subarray(e+1),n))}}}}class F extends TransformStream{constructor(){super(new P)}}async function C(e){let t;const n=[],r=e.getReader();let i;for(;;){const{done:e,value:s}=await r.read();if(e)break;const o=n.at(-1);if(o)if(Array.isArray(o))switch(s.type){case B.Integer:o.push(I(s.value));break;case B.ByteString:o.push(N(s.value));break;case B.DictionaryStart:{const e=Object.create(null);o.push(e),n.push(e);break}case B.ListStart:{const e=[];o.push(e),n.push(e);break}case B.ListEnd:n.pop();break;default:throw new SyntaxError(`Unexpected token: ${JSON.stringify(s)}`)}else if(void 0===i)switch(s.type){case B.ByteString:i=N(s.value);break;case B.DictionaryEnd:n.pop();break;default:throw new SyntaxError(`Unexpected token: ${JSON.stringify(s)}`)}else{switch(s.type){case B.Integer:o[i]=I(s.value);break;case B.ByteString:o[i]=N(s.value);break;case B.DictionaryStart:{const e=Object.create(null);o[i]=e,n.push(e);break}case B.ListStart:{const e=[];o[i]=e,n.push(e);break}default:throw new SyntaxError(`Unexpected token: ${JSON.stringify(s)}`)}i=void 0}else{if(void 0!==t)throw new SyntaxError(`Unexpected token: ${JSON.stringify(s)}`);switch(s.type){case B.Integer:t=I(s.value);break;case B.ByteString:t=N(s.value);break;case B.DictionaryStart:{const e=Object.create(null);n.push(e),t=e;break}case B.ListStart:{const e=[];n.push(e),t=e;break}default:throw new SyntaxError(`Unexpected token: ${JSON.stringify(s)}`)}}}if(n.length)throw new Error("Unexpected end of token stream");return t}async function x(e){const t=new F,n=e.pipeThrough(t);return await C(n)}function I(e){let t=0,n=!0;for(const[r,i]of e.entries()){if(0===r&&i===f){n=!1;continue}if(1===r&&!n&&i===d)throw new SyntaxError("Negative zero is not a valid integer");if(1===r&&0===t)throw new SyntaxError("Leading zeros are not allowed");if(!w(i))throw new SyntaxError(`Unexpected byte: ${i}`);const e=i-d;(n&&"number"==typeof t&&t>(Number.MAX_SAFE_INTEGER-e)/10||!n&&"number"==typeof t&&t<(Number.MIN_SAFE_INTEGER+e)/10)&&(t=BigInt(t)),t="number"==typeof t?n?10*t+e:10*t-e:n?10n*t+BigInt(e):10n*t-BigInt(e)}return t}function N(e){return(new TextDecoder).decode(e)}n(913);class H extends Error{constructor(e,t){super(((e,...t)=>{let n=e;return t.length>0&&(n+=` :: ${JSON.stringify(t)}`),n})(e,t)),this.name=e,this.details=t}}class M{constructor(){this.promise=new Promise(((e,t)=>{this.resolve=e,this.reject=t}))}}function Y(e){const t=e.map((e=>Promise.resolve(e).then((e=>function(e){if(e instanceof Response){if(e.body)return e.body.getReader();throw new H("opaque-streams-source",{type:e.type})}return e instanceof ReadableStream?e.getReader():new Response(e).body.getReader()}(e))))),n=new M;let r=0;const i=new ReadableStream({pull(e){return t[r].then((e=>e.read())).then((i=>{if(i.done)return r++,r>=t.length?(e.close(),void n.resolve()):this.pull(e);e.enqueue(i.value)})).catch((e=>{throw n.reject(e),e}))},cancel(){n.resolve()}});return{done:n.promise,stream:i}}n(1);const D=new Uint8Array(32);class O{blockCount=0;merkleLeaves=[];blocksPerPiece;constructor(e){this.blocksPerPiece=e}async transform(e,t){let r;++this.blockCount;try{r=new Uint8Array(await crypto.subtle.digest("SHA-256",e))}catch{const{default:t}=await Promise.resolve().then(n.bind(n,673)),i=new t("SHA-256","UINT8ARRAY");i.update(e),r=i.getHash("UINT8ARRAY")}this.merkleLeaves.push(r),this.merkleLeaves.length===this.blocksPerPiece&&(t.enqueue(this.merkleLeaves),this.merkleLeaves=[])}flush(e){if(0===this.blockCount)return;let t=0;if(this.blockCount<this.blocksPerPiece)t=v(this.blockCount)-this.blockCount;else{const e=this.blockCount%this.blocksPerPiece;e>0&&(t=this.blocksPerPiece-e)}if(t>0)for(let e=0;e<t;++e)this.merkleLeaves.push(D);this.merkleLeaves.length>0&&e.enqueue(this.merkleLeaves)}}class z extends TransformStream{constructor(e){super(new O(e))}}class ${residuePointer=0;chunkLength;residue;opts;constructor(e,t={padding:!1}){this.chunkLength=e,this.opts=t,this.residue=new Uint8Array(this.chunkLength)}transform(e,t){for(;this.residuePointer+e.byteLength>=this.chunkLength;){const n=this.chunkLength-this.residuePointer;this.residue.set(e.subarray(0,n),this.residuePointer),this.residuePointer=0,t.enqueue(new Uint8Array(this.residue)),e=e.subarray(n)}this.residue.set(e,this.residuePointer),this.residuePointer+=e.byteLength}flush(e){this.residuePointer<=0||(this.opts.padding?(this.residue.set(new Uint8Array(this.chunkLength-this.residuePointer),this.residuePointer),e.enqueue(this.residue)):e.enqueue(this.residue.subarray(0,this.residuePointer)))}}class q extends TransformStream{constructor(e,t={padding:!1}){super(new $(e,t))}}class K{updateProgress;constructor(e){this.updateProgress=e}async transform(e,t){t.enqueue(await L(e)),this.updateProgress&&await this.updateProgress()}}class X extends TransformStream{constructor(e){super(new K(e))}}class _{leafCount=0;merkleLeaves=[];blocksPerPiece;constructor(e){this.blocksPerPiece=e}transform(e){++this.leafCount,this.merkleLeaves.push(e)}async flush(e){const t=v(this.leafCount)-this.leafCount;if(t>0){const e=await this.padLeafPromise;for(let n=0;n<t;++n)this.merkleLeaves.push(e)}e.enqueue(this.merkleLeaves)}get padLeafPromise(){return L(Array(this.blocksPerPiece).fill(new Uint8Array(32)))}}class j extends TransformStream{constructor(e){super(new _(e))}}class V{updateProgress;constructor(e){this.updateProgress=e}async transform(e,t){let r;try{r=new Uint8Array(await crypto.subtle.digest("SHA-1",e))}catch{const{default:t}=await Promise.resolve().then(n.bind(n,211)),i=new t("SHA-1","UINT8ARRAY");i.update(e),r=i.getHash("UINT8ARRAY")}t.enqueue(r),this.updateProgress&&await this.updateProgress()}}class J extends TransformStream{constructor(e){super(new V(e))}}function W(e){return e instanceof File}function Z(e){return!G(e)&&!W(e)&&e.isDirectory}function Q(e){return!G(e)&&!W(e)&&e.isFile}function G(e){try{if(e instanceof FileSystemHandle&&"directory"===e.kind)return!0}catch(e){}return!1}function ee(e){try{if(e instanceof FileSystemHandle&&"file"===e.kind)return!0}catch(e){}return!1}function te(e){return new Promise(((t,n)=>{e.readEntries(t,n)}))}async function*ne(e){const t=e.createReader();let n=[];do{n=await te(t);for(const e of n)yield e}while(n.length>0)}function re(e){return new Promise(((t,n)=>{e.file(t,n)}))}const ie={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};let se;const oe=new Uint8Array(16);function ae(){if(!se&&(se="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!se))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return se(oe)}const ue=[];for(let e=0;e<256;++e)ue.push((e+256).toString(16).slice(1));const ce=function(e,t,n){if(ie.randomUUID&&!t&&!e)return ie.randomUUID();const r=(e=e||{}).random||(e.rng||ae)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(let e=0;e<16;++e)t[n+e]=r[e];return t}return function(e,t=0){return(ue[e[t+0]]+ue[e[t+1]]+ue[e[t+2]]+ue[e[t+3]]+"-"+ue[e[t+4]]+ue[e[t+5]]+"-"+ue[e[t+6]]+ue[e[t+7]]+"-"+ue[e[t+8]]+ue[e[t+9]]+"-"+ue[e[t+10]]+ue[e[t+11]]+ue[e[t+12]]+ue[e[t+13]]+ue[e[t+14]]+ue[e[t+15]]).toLowerCase()}(r)};function he(e,t){if(t.size>1||0===t.size)return{name:e??ce(),commonDir:void 0};const[n,r]=t.entries().next().value;return de(r)?{name:n,commonDir:void 0}:{name:e??n,commonDir:n}}async function le(e,{sort:t=!0,compareFunction:n=me,polyfillWebkitRelativePath:r=!0}={sort:!0,compareFunction:me,polyfillWebkitRelativePath:!0}){let i=0,s=0;const o=new WeakMap,a=new WeakMap,u=new WeakMap,c=["file tree",[]],h=[c];let l=!1;for await(const t of e)await f(t);return{fileTree:fe(c[1],l),traverseTree:function*e(t){if(ge(t))for(const n of t.values())yield*e(n);else yield[t,u.get(t)]},totalFileSize:i,totalFileCount:s};async function f(e){const p=h.at(-1);if(!p)throw new Error("This is a bug");const d=W(e),g=G(e),w=Z(e),m=ee(e),b=Q(e);if(g||w){const r=e.name,{index:i,result:s}=y(p[1],r,n);let o=s;if(we(o))throw new Error("A same name file already exists");if(ye(o)&&g){const t=a.get(o);if(!t||!await e.isSameEntry(t))throw new Error("File system handle not match")}o||(o=[r,[]],t?p[1].splice(i,0,o):p[1].push(o),g&&a.set(o,e)),h.push(o);for await(const t of g?e.values():ne(e))await f(t);o[1]=new Map(o[1]),h.pop()}else if(m||b){const a=e.name,{index:c,result:l}=y(p[1],a,n);let f=l;if(we(f)&&m){const t=o.get(f);if(!t||!await e.isSameEntry(t))throw new Error("A same name file already exists")}if(ye(f))throw new Error("A same name directory already exists");if(f)return;const d=await(m?e.getFile():re(e)),g=d.size;if(r){const e=h.reduce(((e,t,n)=>0===n?e:e+t[0]+"/"),"")+d.name;Object.defineProperty(d,"webkitRelativePath",{configurable:!0,enumerable:!0,get:()=>e})}const w={"":{length:g}};f=[a,w],t?p[1].splice(c,0,f):p[1].push(f),m&&o.set(f,e),u.set(w,d),i+=g,s+=1}else{if(!d)throw new Error("Unrecognized type of input");{r&&""===e.webkitRelativePath&&Object.defineProperty(e,"webkitRelativePath",{configurable:!0,enumerable:!0,get:()=>e.name});const o=(e.webkitRelativePath||e.name).split("/"),a=[c];for(const[r,c]of o.entries()){r>=1&&(l=!0);const h=a.at(-1);if(!h)throw new Error("This is a bug");const{index:f,result:p}=y(h[1],c,n);if(r<o.length-1){let e=p;if(we(e))throw new Error("A same name file already exists");e||(e=[c,[]],t?h[1].splice(f,0,e):h[1].push(e)),a.push(e)}else{let n=p;if(ye(n))throw new Error("A same name directory already exists");if(n)return;const r=e.size,o={"":{length:r}};n=[c,o],t?h[1].splice(f,0,n):h[1].push(n),u.set(o,e),i+=r,s+=1}}}}}}function fe(e,t=!1){return t&&pe(e),new Map(e)}function pe(e){for(const t of e)if(ye(t)){const e=t[1];pe(e),t[1]=new Map(e)}}function de(e){return!!e&&""in e}function ge(e){return e instanceof Map}function we(e){return!!e&&""in e[1]}function ye(e){return!!e&&!(""in e[1])}function me(e,t){return e[0]<t?-1:e[0]>t?1:0}var be;!function(e){e.V1="v1",e.V2="v2",e.HYBRID="hybrid"}(be||(be={}));const ve=16384;var Le;!function(e){e[e["16KB"]=16384]="16KB",e[e["32KB"]=32768]="32KB",e[e["64KB"]=65536]="64KB",e[e["128KB"]=131072]="128KB",e[e["256KB"]=262144]="256KB",e[e["512KB"]=524288]="512KB",e[e["1MB"]=1048576]="1MB",e[e["2MB"]=2097152]="2MB",e[e["4MB"]=4194304]="4MB",e[e["8MB"]=8388608]="8MB",e[e["16MB"]=16777216]="16MB",e[e["32MB"]=33554432]="32MB"}(Le||(Le={}));const ke={type:be.V1,addCreatedBy:!0,addCreationDate:!0,addPaddingFiles:!1,blockLength:ve,pieceLength:NaN,sortFiles:!0,isPrivate:!1},Ae={type:be.V2,addCreatedBy:!0,addCreationDate:!0,blockLength:ve,pieceLength:NaN,metaVersion:2,isPrivate:!1},Ee={type:be.HYBRID,addCreatedBy:!0,addCreationDate:!0,blockLength:ve,pieceLength:NaN,metaVersion:2,isPrivate:!1};function Re(e,t){let n=0;for(const r of e)n+=Math.ceil(r.size/t);return n}async function Ue(e,t={type:be.V1},n){switch(t.type){case be.V1:return await async function(e,t,n){const r={...ke,...t},{fileTree:i,traverseTree:s,totalFileCount:o,totalFileSize:a}=await le(e,{sort:r.sortFiles});if(0===o)return;const u=[];for(const[,e]of s(i))u.push(e);isNaN(r.pieceLength)&&(r.pieceLength=Ce(a,r.blockLength)),0!=(r.pieceLength&r.pieceLength-1)&&console.warn(`piece length ${r.pieceLength} is not a power of 2`),r.announceList=Fe(r.announceList),void 0===r.announce&&void 0!==r.announceList&&(r.announce=r.announceList[0]?.[0]);const[c,h]=Pe(0,n),{commonDir:l,name:f}=he(r.name,i);let p;if(r.name=f,r.addPaddingFiles){const e=Re(u,r.pieceLength);await h(e);const t=[],n=o-1;for(let e=n;e>=0;--e){const i=u[e];if(t.unshift(Promise.resolve(Te(i.stream(),{pieceLength:r.pieceLength,padding:e!==n,updateProgress:c}))),e===n)continue;const s=i.size%r.pieceLength;if(0===s)continue;const o=Be(r.pieceLength-s,l);u.splice(e+1,0,o)}p=Y(t).stream}else{const e=Math.ceil(a/r.pieceLength);await h(e);const{stream:t}=Y(u.map((e=>Promise.resolve(e.stream()))));p=Te(t,{pieceLength:r.pieceLength,padding:!1,updateProgress:c})}return{...void 0===r.announce?{}:{announce:r.announce},...void 0===r.announceList?{}:{"announce-list":r.announceList},...void 0===r.comment?{}:{comment:r.comment},...r.addCreatedBy?{"created by":"torrefy v2.0.3"}:{},...r.addCreationDate?{"creation date":Date.now()/1e3>>0}:{},info:{...o>1?{files:u.map((e=>{const t=(e.webkitRelativePath||e.name).split("/");return void 0!==l&&t.shift(),{...e.padding?{attr:"p"}:{},length:e.size,path:t}}))}:{length:a},name:r.name,"piece length":r.pieceLength,pieces:await new Response(p).arrayBuffer(),...r.isPrivate?{private:!0}:{}}}}(e,t,n);case be.V2:return await async function(e,t,n){const r={...Ae,...t},{fileTree:i,traverseTree:s,totalFileCount:o,totalFileSize:a}=await le(e);if(0===o)return;const u=[],c=[];for(const[e,t]of s(i))u.push(t),c.push([e,t]);if(isNaN(r.pieceLength)&&(r.pieceLength=Ce(a,r.blockLength)),r.pieceLength<r.blockLength)throw new Error(`piece length ${r.pieceLength} is smaller than block length ${r.blockLength}`);if(0!=(r.pieceLength&r.pieceLength-1))throw new Error(`piece length ${r.pieceLength} is not a power of 2`);const h=r.pieceLength/r.blockLength;r.announceList=Fe(r.announceList),void 0===r.announce&&void 0!==r.announceList&&(r.announce=r.announceList[0]?.[0]);const l=Re(u,r.pieceLength),[f]=Pe(l,n),{name:p}=he(r.name,i);r.name=p;const d=new Map;return await Promise.all(c.map((async([e,t])=>{await Se(t.stream(),d,e,{blockLength:r.blockLength,pieceLength:r.pieceLength,blocksPerPiece:h,updateProgress:f})}))),{...void 0===r.announce?{}:{announce:r.announce},...void 0===r.announceList?{}:{"announce-list":r.announceList},...void 0===r.comment?{}:{comment:r.comment},...r.addCreatedBy?{"created by":"torrefy v2.0.3"}:{},...r.addCreationDate?{"creation date":Date.now()/1e3>>0}:{},info:{"file tree":i,"meta version":r.metaVersion,name:r.name,"piece length":r.pieceLength,...r.isPrivate?{private:!0}:{}},"piece layers":d}}(e,t,n);case be.HYBRID:return await async function(e,t,n){const r={...Ee,...t},{fileTree:i,traverseTree:s,totalFileCount:o,totalFileSize:a}=await le(e);if(0===o)return;const u=[],c=[];for(const[e,t]of s(i))u.push(t),c.push([e,t]);if(isNaN(r.pieceLength)&&(r.pieceLength=Ce(a,r.blockLength)),r.pieceLength<r.blockLength)throw new Error(`piece length ${r.pieceLength} is smaller than block length ${r.blockLength}`);if(0!=(r.pieceLength&r.pieceLength-1))throw new Error(`piece length ${r.pieceLength} is not a power of 2`);const h=r.pieceLength/r.blockLength;r.announceList=Fe(r.announceList),void 0===r.announce&&void 0!==r.announceList&&(r.announce=r.announceList[0]?.[0]);const[l]=Pe(2*Re(u,r.pieceLength),n),{commonDir:f,name:p}=he(r.name,i);r.name=p;const d=new Map,g=[],w=o-1;let y=-1;for(const[e,t]of c){++y;const[n,i]=t.stream().tee();if(g.unshift(Promise.resolve(Te(n,{pieceLength:r.pieceLength,padding:y!==w,updateProgress:l}))),await Se(i,d,e,{blockLength:r.blockLength,pieceLength:r.pieceLength,blocksPerPiece:h,updateProgress:l}),y===w)break;const s=t.size%r.pieceLength;if(0===s)continue;const o=Be(r.pieceLength-s,f);u.splice(y+1,0,o)}const m=Y(g).stream;return{...void 0===r.announce?{}:{announce:r.announce},...void 0===r.announceList?{}:{"announce-list":r.announceList},...void 0===r.comment?{}:{comment:r.comment},...r.addCreatedBy?{"created by":"torrefy v2.0.3"}:{},...r.addCreationDate?{"creation date":Date.now()/1e3>>0}:{},info:{"file tree":i,...o>1?{files:u.map((e=>{const t=(e.webkitRelativePath||e.name).split("/");return void 0!==f&&t.shift(),{...e.padding?{attr:"p"}:{},length:e.size,path:t}}))}:{length:a},"meta version":r.metaVersion,name:r.name,"piece length":r.pieceLength,pieces:await new Response(m).arrayBuffer(),...r.isPrivate?{private:!0}:{}},"piece layers":d}}(e,t,n)}}async function Se(e,t,n,r){const{piecesRootReadableStream:i,pieceLayerReadableStream:s}=function(e,t){const n=e.pipeThrough(new q(t.blockLength)).pipeThrough(new z(t.blocksPerPiece)).pipeThrough(new X(t.updateProgress)),[r,i]=n.tee();return{piecesRootReadableStream:i.pipeThrough(new j(t.blocksPerPiece)).pipeThrough(new X),pieceLayerReadableStream:r}}(e,r),o=new Response(i).arrayBuffer();if(n[""].length>r.pieceLength){const e=new Response(s).arrayBuffer();t.set(await o,await e)}n[""].length>0&&(n[""]["pieces root"]=await o)}function Te(e,t){return e.pipeThrough(new q(t.pieceLength,{padding:t.padding})).pipeThrough(new J(t.updateProgress))}function Be(e,t){const n=new File([new ArrayBuffer(e)],`${e}`,{type:"application/octet-stream"}),r=`.pad/${e}`,i=void 0===t?r:`${t}/${r}`;return Object.defineProperties(n,{webkitRelativePath:{configurable:!0,enumerable:!0,get:()=>i},padding:{configurable:!0,enumerable:!1,get:()=>!0}}),n}function Pe(e,t){const n={current:0,total:e};return[async()=>{t&&await t(++n.current,n.total)},async e=>{n.total="number"==typeof e?e:await e(n.total,n.current)}]}function Fe(e){if(void 0===e)return;const t=[];for(const n of e)0!==n.length&&t.push(n);return 0!==t.length?t:void 0}function Ce(e,t){return Math.max(t,v(e>>>10))}})();var i=r.j$,s=r.nm,o=r.Xz,a=r.ul,u=r.zo,c=r.zM,h=r.pI,l=r.I4,f=r.Fl,p=r.In,d=r.Cj,g=r.t6,w=r.mh,y=r.LQ,m=r.R2,b=r.rJ,v=r.xI,L=r.$$,k=r.e9,A=r.K2,E=r.ZC,R=r.iv,U=r.d2,S=r.vB,T=r.y1,B=r.Hv,P=r.Ue,F=r.Jx,C=r.cv,x=r.Pi,I=r.um,N=r.sK,H=r.Fw,M=r.zE,Y=r.RU,D=r.Xs,O=r.r1,z=r.Kl,$=r.A7,q=r.px,K=r.ZW,X=r.ti,j=r.bX,V=r.Dc,J=r.fp,W=r.Ye,Z=r.Qc,Q=r.hP,G=r.LU,ee=r.yQ,te=r.Zk,ne=r.uh;export{i as BUFF_0,s as BUFF_COLON,o as BUFF_D,a as BUFF_E,u as BUFF_I,c as BUFF_L,h as BUFF_MINUS,l as BYTE_0,f as BYTE_COLON,p as BYTE_D,d as BYTE_E,g as BYTE_I,w as BYTE_L,y as BYTE_MINUS,m as BlockHasher,b as ChunkSplitter,v as CommonPieceLength,L as DEFAULT_BLOCK_LENGTH,k as MerkleRootCalculator,A as MerkleTreeBalancer,E as PieceHasher,R as TokenType,U as Tokenizer,S as TorrentType,T as compareEntryNames,B as concatUint8Arrays,P as create,F as decode,C as encode,x as getEntriesOfDirEntry,I as getFileOfFileEntry,N as getSortedIndex,H as isDigitByte,M as isFile,Y as isFileSystemDirectoryEntry,D as isFileSystemDirectoryHandle,O as isFileSystemFileEntry,z as isFileSystemFileHandle,$ as isFileTreeDirEntry,q as isFileTreeDirNode,K as isFileTreeFileEntry,X as isFileTreeFileNode,j as iterableSort,V as merkleRoot,J as nextPowerOfTwo,W as packEntriesToDirNode,Z as parse,Q as populateFileTree,G as resolveCommonDirAndTorrentName,ee as useArrayBufferPromiseHook,te as useTextPromiseHook,ne as useUint8ArrayStreamHook};

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.torrefy=e():t.torrefy=e()}(self,(()=>(()=>{var t={340:t=>{const e=Symbol("path-store-trunk");class n{constructor(t=[]){this._root=new Map,this._size=0;for(const[e,n]of t)this.set(e,n)}set(t,e){return r.call(this,t,e)}has(t){return o.call(this,t)}get(t){return i.call(this,t)}delete(t){return s.call(this,t)}get size(){return this._size}clear(){this._root.clear(),this._size=0}hasPrefix(t){return u.call(this,t)}get[Symbol.toStringTag](){return"ArrayKeyedMap"}*[Symbol.iterator](){yield*a.call(this)}*entries(){yield*a.call(this)}*keys(){yield*h.call(this)}*values(){yield*c.call(this)}forEach(t,e){f.call(this,t,e)}}function r(t,n){let r=this._root;for(const e of t){let t=r.get(e);t||(t=new Map,r.set(e,t)),r=t}return r.has(e)||(this._size+=1),r.set(e,n),this}function o(t){let n=this._root;for(const e of t){const t=n.get(e);if(!t)return!1;n=t}return n.has(e)}function i(t){let n=this._root;for(const e of t)if(n=n.get(e),!n)return;return n.get(e)}function s(t){let n=this._root;const r=[];for(const e of t){const t=n.get(e);if(!t)return!1;r.unshift({parent:n,child:t,item:e}),n=t}const o=n.delete(e);if(o){this._size-=1;for(const{parent:t,child:e,item:n}of r)0===e.size&&t.delete(n)}return o}function u(t){let e=this._root;for(const n of t)if(e=e.get(n),!e)return!1;return!0}function*a(){const t=[{path:[],map:this._root}];for(;t.length>0;){const{path:n,map:r}=t.pop();for(const[o,i]of r.entries())o===e?yield[n,i]:t.push({path:n.concat([o]),map:i})}}function*h(){for(const[t]of this.entries())yield t}function*c(){for(const[,t]of this.entries())yield t}function f(t,e){for(const[n,r]of this.entries())t.call(e,r,n,this)}t.exports=n},913:()=>{"use strict";try{self["workbox:core:6.5.3"]&&_()}catch(t){}},1:()=>{"use strict";try{self["workbox:streams:6.5.3"]&&_()}catch(t){}},211:(t,e,n)=>{"use strict";n.r(e),n.d(e,{default:()=>g});const r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function o(t,e,n,r){let o,i,s;const u=e||[0],a=(n=n||0)>>>3,h=-1===r?3:0;for(o=0;o<t.length;o+=1)s=o+a,i=s>>>2,u.length<=i&&u.push(0),u[i]|=t[o]<<8*(h+r*(s%4));return{value:u,binLen:8*t.length+n}}function i(t,e,n){switch(e){case"UTF8":case"UTF16BE":case"UTF16LE":break;default:throw new Error("encoding must be UTF8, UTF16BE, or UTF16LE")}switch(t){case"HEX":return function(t,e,r){return function(t,e,n,r){let o,i,s,u;if(0!=t.length%2)throw new Error("String of HEX type must be in byte increments");const a=e||[0],h=(n=n||0)>>>3,c=-1===r?3:0;for(o=0;o<t.length;o+=2){if(i=parseInt(t.substr(o,2),16),isNaN(i))throw new Error("String of HEX type contains invalid characters");for(u=(o>>>1)+h,s=u>>>2;a.length<=s;)a.push(0);a[s]|=i<<8*(c+r*(u%4))}return{value:a,binLen:4*t.length+n}}(t,e,r,n)};case"TEXT":return function(t,r,o){return function(t,e,n,r,o){let i,s,u,a,h,c,f,l,p=0;const d=n||[0],y=(r=r||0)>>>3;if("UTF8"===e)for(f=-1===o?3:0,u=0;u<t.length;u+=1)for(i=t.charCodeAt(u),s=[],128>i?s.push(i):2048>i?(s.push(192|i>>>6),s.push(128|63&i)):55296>i||57344<=i?s.push(224|i>>>12,128|i>>>6&63,128|63&i):(u+=1,i=65536+((1023&i)<<10|1023&t.charCodeAt(u)),s.push(240|i>>>18,128|i>>>12&63,128|i>>>6&63,128|63&i)),a=0;a<s.length;a+=1){for(c=p+y,h=c>>>2;d.length<=h;)d.push(0);d[h]|=s[a]<<8*(f+o*(c%4)),p+=1}else for(f=-1===o?2:0,l="UTF16LE"===e&&1!==o||"UTF16LE"!==e&&1===o,u=0;u<t.length;u+=1){for(i=t.charCodeAt(u),!0===l&&(a=255&i,i=a<<8|i>>>8),c=p+y,h=c>>>2;d.length<=h;)d.push(0);d[h]|=i<<8*(f+o*(c%4)),p+=2}return{value:d,binLen:8*p+r}}(t,e,r,o,n)};case"B64":return function(t,e,o){return function(t,e,n,o){let i,s,u,a,h,c,f,l=0;const p=e||[0],d=(n=n||0)>>>3,y=-1===o?3:0,g=t.indexOf("=");if(-1===t.search(/^[a-zA-Z0-9=+/]+$/))throw new Error("Invalid character in base-64 string");if(t=t.replace(/=/g,""),-1!==g&&g<t.length)throw new Error("Invalid '=' found in base-64 string");for(s=0;s<t.length;s+=4){for(h=t.substr(s,4),a=0,u=0;u<h.length;u+=1)i=r.indexOf(h.charAt(u)),a|=i<<18-6*u;for(u=0;u<h.length-1;u+=1){for(f=l+d,c=f>>>2;p.length<=c;)p.push(0);p[c]|=(a>>>16-8*u&255)<<8*(y+o*(f%4)),l+=1}}return{value:p,binLen:8*l+n}}(t,e,o,n)};case"BYTES":return function(t,e,r){return function(t,e,n,r){let o,i,s,u;const a=e||[0],h=(n=n||0)>>>3,c=-1===r?3:0;for(i=0;i<t.length;i+=1)o=t.charCodeAt(i),u=i+h,s=u>>>2,a.length<=s&&a.push(0),a[s]|=o<<8*(c+r*(u%4));return{value:a,binLen:8*t.length+n}}(t,e,r,n)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(t){throw new Error("ARRAYBUFFER not supported by this environment")}return function(t,e,r){return function(t,e,n,r){return o(new Uint8Array(t),e,n,r)}(t,e,r,n)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(t){throw new Error("UINT8ARRAY not supported by this environment")}return function(t,e,r){return o(t,e,r,n)};default:throw new Error("format must be HEX, TEXT, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}function s(t,e,n,o){switch(t){case"HEX":return function(t){return function(t,e,n,r){const o="0123456789abcdef";let i,s,u="";const a=e/8,h=-1===n?3:0;for(i=0;i<a;i+=1)s=t[i>>>2]>>>8*(h+n*(i%4)),u+=o.charAt(s>>>4&15)+o.charAt(15&s);return r.outputUpper?u.toUpperCase():u}(t,e,n,o)};case"B64":return function(t){return function(t,e,n,o){let i,s,u,a,h,c="";const f=e/8,l=-1===n?3:0;for(i=0;i<f;i+=3)for(a=i+1<f?t[i+1>>>2]:0,h=i+2<f?t[i+2>>>2]:0,u=(t[i>>>2]>>>8*(l+n*(i%4))&255)<<16|(a>>>8*(l+n*((i+1)%4))&255)<<8|h>>>8*(l+n*((i+2)%4))&255,s=0;s<4;s+=1)c+=8*i+6*s<=e?r.charAt(u>>>6*(3-s)&63):o.b64Pad;return c}(t,e,n,o)};case"BYTES":return function(t){return function(t,e,n){let r,o,i="";const s=e/8,u=-1===n?3:0;for(r=0;r<s;r+=1)o=t[r>>>2]>>>8*(u+n*(r%4))&255,i+=String.fromCharCode(o);return i}(t,e,n)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(t){throw new Error("ARRAYBUFFER not supported by this environment")}return function(t){return function(t,e,n){let r;const o=e/8,i=new ArrayBuffer(o),s=new Uint8Array(i),u=-1===n?3:0;for(r=0;r<o;r+=1)s[r]=t[r>>>2]>>>8*(u+n*(r%4))&255;return i}(t,e,n)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(t){throw new Error("UINT8ARRAY not supported by this environment")}return function(t){return function(t,e,n){let r;const o=e/8,i=-1===n?3:0,s=new Uint8Array(o);for(r=0;r<o;r+=1)s[r]=t[r>>>2]>>>8*(i+n*(r%4))&255;return s}(t,e,n)};default:throw new Error("format must be HEX, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}function u(t){const e={outputUpper:!1,b64Pad:"=",outputLen:-1},n=t||{},r="Output length must be a multiple of 8";if(e.outputUpper=n.outputUpper||!1,n.b64Pad&&(e.b64Pad=n.b64Pad),n.outputLen){if(n.outputLen%8!=0)throw new Error(r);e.outputLen=n.outputLen}else if(n.shakeLen){if(n.shakeLen%8!=0)throw new Error(r);e.outputLen=n.shakeLen}if("boolean"!=typeof e.outputUpper)throw new Error("Invalid outputUpper formatting option");if("string"!=typeof e.b64Pad)throw new Error("Invalid b64Pad formatting option");return e}function a(t,e){return t<<e|t>>>32-e}function h(t,e,n){return t^e^n}function c(t,e,n){return t&e^t&n^e&n}function f(t,e){const n=(65535&t)+(65535&e);return(65535&(t>>>16)+(e>>>16)+(n>>>16))<<16|65535&n}function l(t,e,n,r,o){const i=(65535&t)+(65535&e)+(65535&n)+(65535&r)+(65535&o);return(65535&(t>>>16)+(e>>>16)+(n>>>16)+(r>>>16)+(o>>>16)+(i>>>16))<<16|65535&i}function p(t){return[1732584193,4023233417,2562383102,271733878,3285377520]}function d(t,e){let n,r,o,i,s,u,p;const d=[];for(n=e[0],r=e[1],o=e[2],i=e[3],s=e[4],p=0;p<80;p+=1)d[p]=p<16?t[p]:a(d[p-3]^d[p-8]^d[p-14]^d[p-16],1),u=p<20?l(a(n,5),(y=r)&o^~y&i,s,1518500249,d[p]):p<40?l(a(n,5),h(r,o,i),s,1859775393,d[p]):p<60?l(a(n,5),c(r,o,i),s,2400959708,d[p]):l(a(n,5),h(r,o,i),s,3395469782,d[p]),s=i,i=o,o=a(r,30),r=n,n=u;var y;return e[0]=f(n,e[0]),e[1]=f(r,e[1]),e[2]=f(o,e[2]),e[3]=f(i,e[3]),e[4]=f(s,e[4]),e}function y(t,e,n,r){let o;const i=15+(e+65>>>9<<4),s=e+n;for(;t.length<=i;)t.push(0);for(t[e>>>5]|=128<<24-e%32,t[i]=4294967295&s,t[i-1]=s/4294967296|0,o=0;o<t.length;o+=16)r=d(t.slice(o,o+16),r);return r}class g extends class{constructor(t,e,n){const r=n||{};if(this.t=e,this.i=r.encoding||"UTF8",this.numRounds=r.numRounds||1,isNaN(this.numRounds)||this.numRounds!==parseInt(this.numRounds,10)||1>this.numRounds)throw new Error("numRounds must a integer >= 1");this.o=t,this.h=[],this.u=0,this.l=!1,this.A=0,this.p=!1,this.R=[],this.U=[]}update(t){let e,n=0;const r=this.T>>>5,o=this.F(t,this.h,this.u),i=o.binLen,s=o.value,u=i>>>5;for(e=0;e<u;e+=r)n+this.T<=i&&(this.m=this.g(s.slice(e,e+r),this.m),n+=this.T);return this.A+=n,this.h=s.slice(n>>>5),this.u=i%this.T,this.l=!0,this}getHash(t,e){let n,r,o=this.B;const i=u(e);if(this.v){if(-1===i.outputLen)throw new Error("Output length must be specified in options");o=i.outputLen}const a=s(t,o,this.Y,i);if(this.p&&this.H)return a(this.H(i));for(r=this.C(this.h.slice(),this.u,this.A,this.I(this.m),o),n=1;n<this.numRounds;n+=1)this.v&&o%32!=0&&(r[r.length-1]&=16777215>>>24-o%32),r=this.C(r,o,0,this.L(this.o),o);return a(r)}setHMACKey(t,e,n){if(!this.M)throw new Error("Variant does not support HMAC");if(this.l)throw new Error("Cannot set MAC key after calling update");const r=i(e,(n||{}).encoding||"UTF8",this.Y);this.N(r(t))}N(t){const e=this.T>>>3,n=e/4-1;let r;if(1!==this.numRounds)throw new Error("Cannot set numRounds with MAC");if(this.p)throw new Error("MAC key already set");for(e<t.binLen/8&&(t.value=this.C(t.value,t.binLen,0,this.L(this.o),this.B));t.value.length<=n;)t.value.push(0);for(r=0;r<=n;r+=1)this.R[r]=909522486^t.value[r],this.U[r]=1549556828^t.value[r];this.m=this.g(this.R,this.m),this.A=this.T,this.p=!0}getHMAC(t,e){const n=u(e);return s(t,this.B,this.Y,n)(this.S())}S(){let t;if(!this.p)throw new Error("Cannot call getHMAC without first setting MAC key");const e=this.C(this.h.slice(),this.u,this.A,this.I(this.m),this.B);return t=this.g(this.U,this.L(this.o)),t=this.C(e,this.B,this.T,t,this.B),t}}{constructor(t,e,n){if("SHA-1"!==t)throw new Error("Chosen SHA variant is not supported");super(t,e,n);const r=n||{};this.M=!0,this.H=this.S,this.Y=-1,this.F=i(this.t,this.i,this.Y),this.g=d,this.I=function(t){return t.slice()},this.L=p,this.C=y,this.m=[1732584193,4023233417,2562383102,271733878,3285377520],this.T=512,this.B=160,this.v=!1,r.hmacKey&&this.N(function(t,e,n,r){const o="hmacKey must include a value and format";if(!e)throw new Error(o);if(void 0===e.value||!e.format)throw new Error(o);return i(e.format,e.encoding||"UTF8",n)(e.value)}(0,r.hmacKey,this.Y))}}},673:(t,e,n)=>{"use strict";n.r(e),n.d(e,{default:()=>R});const r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function o(t,e,n,r){let o,i,s;const u=e||[0],a=(n=n||0)>>>3,h=-1===r?3:0;for(o=0;o<t.length;o+=1)s=o+a,i=s>>>2,u.length<=i&&u.push(0),u[i]|=t[o]<<8*(h+r*(s%4));return{value:u,binLen:8*t.length+n}}function i(t,e,n){switch(e){case"UTF8":case"UTF16BE":case"UTF16LE":break;default:throw new Error("encoding must be UTF8, UTF16BE, or UTF16LE")}switch(t){case"HEX":return function(t,e,r){return function(t,e,n,r){let o,i,s,u;if(0!=t.length%2)throw new Error("String of HEX type must be in byte increments");const a=e||[0],h=(n=n||0)>>>3,c=-1===r?3:0;for(o=0;o<t.length;o+=2){if(i=parseInt(t.substr(o,2),16),isNaN(i))throw new Error("String of HEX type contains invalid characters");for(u=(o>>>1)+h,s=u>>>2;a.length<=s;)a.push(0);a[s]|=i<<8*(c+r*(u%4))}return{value:a,binLen:4*t.length+n}}(t,e,r,n)};case"TEXT":return function(t,r,o){return function(t,e,n,r,o){let i,s,u,a,h,c,f,l,p=0;const d=n||[0],y=(r=r||0)>>>3;if("UTF8"===e)for(f=-1===o?3:0,u=0;u<t.length;u+=1)for(i=t.charCodeAt(u),s=[],128>i?s.push(i):2048>i?(s.push(192|i>>>6),s.push(128|63&i)):55296>i||57344<=i?s.push(224|i>>>12,128|i>>>6&63,128|63&i):(u+=1,i=65536+((1023&i)<<10|1023&t.charCodeAt(u)),s.push(240|i>>>18,128|i>>>12&63,128|i>>>6&63,128|63&i)),a=0;a<s.length;a+=1){for(c=p+y,h=c>>>2;d.length<=h;)d.push(0);d[h]|=s[a]<<8*(f+o*(c%4)),p+=1}else for(f=-1===o?2:0,l="UTF16LE"===e&&1!==o||"UTF16LE"!==e&&1===o,u=0;u<t.length;u+=1){for(i=t.charCodeAt(u),!0===l&&(a=255&i,i=a<<8|i>>>8),c=p+y,h=c>>>2;d.length<=h;)d.push(0);d[h]|=i<<8*(f+o*(c%4)),p+=2}return{value:d,binLen:8*p+r}}(t,e,r,o,n)};case"B64":return function(t,e,o){return function(t,e,n,o){let i,s,u,a,h,c,f,l=0;const p=e||[0],d=(n=n||0)>>>3,y=-1===o?3:0,g=t.indexOf("=");if(-1===t.search(/^[a-zA-Z0-9=+/]+$/))throw new Error("Invalid character in base-64 string");if(t=t.replace(/=/g,""),-1!==g&&g<t.length)throw new Error("Invalid '=' found in base-64 string");for(s=0;s<t.length;s+=4){for(h=t.substr(s,4),a=0,u=0;u<h.length;u+=1)i=r.indexOf(h.charAt(u)),a|=i<<18-6*u;for(u=0;u<h.length-1;u+=1){for(f=l+d,c=f>>>2;p.length<=c;)p.push(0);p[c]|=(a>>>16-8*u&255)<<8*(y+o*(f%4)),l+=1}}return{value:p,binLen:8*l+n}}(t,e,o,n)};case"BYTES":return function(t,e,r){return function(t,e,n,r){let o,i,s,u;const a=e||[0],h=(n=n||0)>>>3,c=-1===r?3:0;for(i=0;i<t.length;i+=1)o=t.charCodeAt(i),u=i+h,s=u>>>2,a.length<=s&&a.push(0),a[s]|=o<<8*(c+r*(u%4));return{value:a,binLen:8*t.length+n}}(t,e,r,n)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(t){throw new Error("ARRAYBUFFER not supported by this environment")}return function(t,e,r){return function(t,e,n,r){return o(new Uint8Array(t),e,n,r)}(t,e,r,n)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(t){throw new Error("UINT8ARRAY not supported by this environment")}return function(t,e,r){return o(t,e,r,n)};default:throw new Error("format must be HEX, TEXT, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}function s(t,e,n,o){switch(t){case"HEX":return function(t){return function(t,e,n,r){const o="0123456789abcdef";let i,s,u="";const a=e/8,h=-1===n?3:0;for(i=0;i<a;i+=1)s=t[i>>>2]>>>8*(h+n*(i%4)),u+=o.charAt(s>>>4&15)+o.charAt(15&s);return r.outputUpper?u.toUpperCase():u}(t,e,n,o)};case"B64":return function(t){return function(t,e,n,o){let i,s,u,a,h,c="";const f=e/8,l=-1===n?3:0;for(i=0;i<f;i+=3)for(a=i+1<f?t[i+1>>>2]:0,h=i+2<f?t[i+2>>>2]:0,u=(t[i>>>2]>>>8*(l+n*(i%4))&255)<<16|(a>>>8*(l+n*((i+1)%4))&255)<<8|h>>>8*(l+n*((i+2)%4))&255,s=0;s<4;s+=1)c+=8*i+6*s<=e?r.charAt(u>>>6*(3-s)&63):o.b64Pad;return c}(t,e,n,o)};case"BYTES":return function(t){return function(t,e,n){let r,o,i="";const s=e/8,u=-1===n?3:0;for(r=0;r<s;r+=1)o=t[r>>>2]>>>8*(u+n*(r%4))&255,i+=String.fromCharCode(o);return i}(t,e,n)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(t){throw new Error("ARRAYBUFFER not supported by this environment")}return function(t){return function(t,e,n){let r;const o=e/8,i=new ArrayBuffer(o),s=new Uint8Array(i),u=-1===n?3:0;for(r=0;r<o;r+=1)s[r]=t[r>>>2]>>>8*(u+n*(r%4))&255;return i}(t,e,n)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(t){throw new Error("UINT8ARRAY not supported by this environment")}return function(t){return function(t,e,n){let r;const o=e/8,i=-1===n?3:0,s=new Uint8Array(o);for(r=0;r<o;r+=1)s[r]=t[r>>>2]>>>8*(i+n*(r%4))&255;return s}(t,e,n)};default:throw new Error("format must be HEX, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}const u=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],a=[3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428],h=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225];function c(t){const e={outputUpper:!1,b64Pad:"=",outputLen:-1},n=t||{},r="Output length must be a multiple of 8";if(e.outputUpper=n.outputUpper||!1,n.b64Pad&&(e.b64Pad=n.b64Pad),n.outputLen){if(n.outputLen%8!=0)throw new Error(r);e.outputLen=n.outputLen}else if(n.shakeLen){if(n.shakeLen%8!=0)throw new Error(r);e.outputLen=n.shakeLen}if("boolean"!=typeof e.outputUpper)throw new Error("Invalid outputUpper formatting option");if("string"!=typeof e.b64Pad)throw new Error("Invalid b64Pad formatting option");return e}function f(t,e){return t>>>e|t<<32-e}function l(t,e){return t>>>e}function p(t,e,n){return t&e^~t&n}function d(t,e,n){return t&e^t&n^e&n}function y(t){return f(t,2)^f(t,13)^f(t,22)}function g(t,e){const n=(65535&t)+(65535&e);return(65535&(t>>>16)+(e>>>16)+(n>>>16))<<16|65535&n}function w(t,e,n,r){const o=(65535&t)+(65535&e)+(65535&n)+(65535&r);return(65535&(t>>>16)+(e>>>16)+(n>>>16)+(r>>>16)+(o>>>16))<<16|65535&o}function m(t,e,n,r,o){const i=(65535&t)+(65535&e)+(65535&n)+(65535&r)+(65535&o);return(65535&(t>>>16)+(e>>>16)+(n>>>16)+(r>>>16)+(o>>>16)+(i>>>16))<<16|65535&i}function b(t){return f(t,7)^f(t,18)^l(t,3)}function A(t){return f(t,6)^f(t,11)^f(t,25)}function v(t){let e;return e="SHA-224"==t?a.slice():h.slice(),e}function E(t,e){let n,r,o,i,s,a,h,c,v,E,R;const U=[];for(n=e[0],r=e[1],o=e[2],i=e[3],s=e[4],a=e[5],h=e[6],c=e[7],R=0;R<64;R+=1)U[R]=R<16?t[R]:w(f(S=U[R-2],17)^f(S,19)^l(S,10),U[R-7],b(U[R-15]),U[R-16]),v=m(c,A(s),p(s,a,h),u[R],U[R]),E=g(y(n),d(n,r,o)),c=h,h=a,a=s,s=g(i,v),i=o,o=r,r=n,n=g(v,E);var S;return e[0]=g(n,e[0]),e[1]=g(r,e[1]),e[2]=g(o,e[2]),e[3]=g(i,e[3]),e[4]=g(s,e[4]),e[5]=g(a,e[5]),e[6]=g(h,e[6]),e[7]=g(c,e[7]),e}class R extends class{constructor(t,e,n){const r=n||{};if(this.t=e,this.i=r.encoding||"UTF8",this.numRounds=r.numRounds||1,isNaN(this.numRounds)||this.numRounds!==parseInt(this.numRounds,10)||1>this.numRounds)throw new Error("numRounds must a integer >= 1");this.o=t,this.h=[],this.u=0,this.A=!1,this.l=0,this.p=!1,this.R=[],this.U=[]}update(t){let e,n=0;const r=this.T>>>5,o=this.F(t,this.h,this.u),i=o.binLen,s=o.value,u=i>>>5;for(e=0;e<u;e+=r)n+this.T<=i&&(this.m=this.g(s.slice(e,e+r),this.m),n+=this.T);return this.l+=n,this.h=s.slice(n>>>5),this.u=i%this.T,this.A=!0,this}getHash(t,e){let n,r,o=this.B;const i=c(e);if(this.H){if(-1===i.outputLen)throw new Error("Output length must be specified in options");o=i.outputLen}const u=s(t,o,this.v,i);if(this.p&&this.Y)return u(this.Y(i));for(r=this.C(this.h.slice(),this.u,this.l,this.S(this.m),o),n=1;n<this.numRounds;n+=1)this.H&&o%32!=0&&(r[r.length-1]&=16777215>>>24-o%32),r=this.C(r,o,0,this.I(this.o),o);return u(r)}setHMACKey(t,e,n){if(!this.L)throw new Error("Variant does not support HMAC");if(this.A)throw new Error("Cannot set MAC key after calling update");const r=i(e,(n||{}).encoding||"UTF8",this.v);this.M(r(t))}M(t){const e=this.T>>>3,n=e/4-1;let r;if(1!==this.numRounds)throw new Error("Cannot set numRounds with MAC");if(this.p)throw new Error("MAC key already set");for(e<t.binLen/8&&(t.value=this.C(t.value,t.binLen,0,this.I(this.o),this.B));t.value.length<=n;)t.value.push(0);for(r=0;r<=n;r+=1)this.R[r]=909522486^t.value[r],this.U[r]=1549556828^t.value[r];this.m=this.g(this.R,this.m),this.l=this.T,this.p=!0}getHMAC(t,e){const n=c(e);return s(t,this.B,this.v,n)(this.N())}N(){let t;if(!this.p)throw new Error("Cannot call getHMAC without first setting MAC key");const e=this.C(this.h.slice(),this.u,this.l,this.S(this.m),this.B);return t=this.g(this.U,this.I(this.o)),t=this.C(e,this.B,this.T,t,this.B),t}}{constructor(t,e,n){if("SHA-224"!==t&&"SHA-256"!==t)throw new Error("Chosen SHA variant is not supported");super(t,e,n);const r=n||{};this.Y=this.N,this.L=!0,this.v=-1,this.F=i(this.t,this.i,this.v),this.g=E,this.S=function(t){return t.slice()},this.I=v,this.C=function(e,n,r,o){return function(t,e,n,r,o){let i,s;const u=15+(e+65>>>9<<4),a=e+n;for(;t.length<=u;)t.push(0);for(t[e>>>5]|=128<<24-e%32,t[u]=4294967295&a,t[u-1]=a/4294967296|0,i=0;i<t.length;i+=16)r=E(t.slice(i,i+16),r);return s="SHA-224"===o?[r[0],r[1],r[2],r[3],r[4],r[5],r[6]]:r,s}(e,n,r,o,t)},this.m=v(t),this.T=512,this.B="SHA-224"===t?224:256,this.H=!1,r.hmacKey&&this.M(function(t,e,n,r){const o="hmacKey must include a value and format";if(!e)throw new Error(o);if(void 0===e.value||!e.format)throw new Error(o);return i(e.format,e.encoding||"UTF8",n)(e.value)}(0,r.hmacKey,this.v))}}}},e={};function n(r){var o=e[r];if(void 0!==o)return o.exports;var i=e[r]={exports:{}};return t[r](i,i.exports,n),i.exports}n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var r={};return(()=>{"use strict";n.r(r),n.d(r,{ArrayKeyedMap:()=>b(),BUFF_D:()=>v,BUFF_E:()=>E,BUFF_L:()=>A,CommonPieceLength:()=>V,DEFAULT_BLOCK_LENGTH:()=>$,TorrentType:()=>K,calculatePieceLength:()=>w,collapseAnnounceList:()=>p,create:()=>Z,decideName:()=>g,decode:()=>Y,encode:()=>U,getCommonDir:()=>d,getSortedIndex:()=>a,iterableSort:()=>h,makeTokenizer:()=>M,merkleRoot:()=>f,nextPowerOfTwo:()=>l,padFiles:()=>y,parse:()=>H,parseFileTree:()=>c,useArrayBufferPromiseHook:()=>T,useTextPromiseHook:()=>k,useUint8ArrayStreamHook:()=>B});const t={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};let e;const o=new Uint8Array(16);function i(){if(!e&&(e="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!e))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return e(o)}const s=[];for(let t=0;t<256;++t)s.push((t+256).toString(16).slice(1));const u=function(e,n,r){if(t.randomUUID&&!n&&!e)return t.randomUUID();const o=(e=e||{}).random||(e.rng||i)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,n){r=r||0;for(let t=0;t<16;++t)n[r+t]=o[t];return n}return function(t,e=0){return(s[t[e+0]]+s[t[e+1]]+s[t[e+2]]+s[t[e+3]]+"-"+s[t[e+4]]+s[t[e+5]]+"-"+s[t[e+6]]+s[t[e+7]]+"-"+s[t[e+8]]+s[t[e+9]]+"-"+s[t[e+10]]+s[t[e+11]]+s[t[e+12]]+s[t[e+13]]+s[t[e+14]]+s[t[e+15]]).toLowerCase()}(o)};function a(t,e,n){let r=0,o=t.length;for(;r<o;){const i=r+o>>>1;n(t[i],e)<0?r=i+1:o=i}return r}function h(t,e){const n=[];for(const r of t)n.splice(a(n,r,e),0,r);return n}function c(t){let e=[];const n=new WeakMap;for(const r of t){const t=(r.webkitRelativePath||r.name).split("/");t.reduce(((e,o,i)=>{let s=e.find((t=>t[0]===o));if(s)return s[1];const u=a(e,o,((t,e)=>t[0]<e?-1:1));if(i===t.length-1){const t={"":{length:r.size}};n.set(t,r),s=[o,t]}else s=[o,[]];return e.splice(u,0,s),s[1]}),e)}let r;1===e.length&&Array.isArray(e[0][1])&&(r=e[0][0],e=e[0][1]);const o=[];return{fileTree:{*[Symbol.iterator](){for(const t of o)yield t},...function t(e){if(Array.isArray(e)){const n={};for(const r of e)n[r[0]]=t(r[1]);return n}{const t=e;return o.push(t),t}}(e)},fileNodeMap:n,commonDir:r}}async function f(t){const e=new Uint8Array(64);for(;t.length>1;){let n=!1;const r=[];for(const o of t)n?(e.set(o,32),r.push(new Uint8Array(await crypto.subtle.digest("SHA-256",e))),n=!1):(e.set(o),n=!0);t=r}return t[0]}function l(t){return 1<<32-Math.clz32(t-1)}function p(t){if(void 0===t)return;const e=[];for(const n of t)0!==n.length&&e.push(n);return 0!==e.length?e:void 0}function d(t){let e;for(const n of t){const t=(n.webkitRelativePath||n.name).split("/");if(1==t.length||(e??=t[0])!==t[0])return}return e}function y(t,e,n){const r=[],o=t.length-1;for(const[i,s]of t.entries()){if(r.push(s),i===o)break;const t=s.size%e;if(0===t)continue;const u=e-t,a=new File([new ArrayBuffer(u)],`${u}`,{type:"application/octet-stream"}),h=`.pad/${u}`,c=void 0===n?h:`${n}/${h}`;Object.defineProperties(a,{webkitRelativePath:{configurable:!0,enumerable:!0,get:()=>c},padding:{configurable:!0,enumerable:!1,get:()=>!0}}),r.push(a)}return r}function g(t,e,n){return void 0===e&&1===n.length?t=n[0].name:t??=e||u(),t}function w(t,e){return Math.max(e,l(t>>>10))}var m=n(340),b=n.n(m);const A=new Uint8Array([108]),v=new Uint8Array([100]),E=new Uint8Array([101]);class R{textEncoder=new TextEncoder;textDecoder=new TextDecoder;data;hooks;isHooking=!1;path=[];constructor(t,e){this.data=t,this.hooks=e}start(t){this.encode(this.data,t),t.close()}encode(t,e){if(null!=t)if("boolean"==typeof t)this.encode(t?1:0,e);else if("number"==typeof t){const n=Math.round(t);e.enqueue(this.textEncoder.encode(`i${n}e`)),n!==t&&(console.warn(`WARNING: Possible data corruption detected with value "${t}":`,`Bencoding only defines support for integers, value was converted to "${n}"`),console.trace())}else if("bigint"==typeof t)e.enqueue(this.textEncoder.encode(`i${t}e`));else if("string"==typeof t){const n=this.textEncoder.encode(t),r=n.byteLength;e.enqueue(this.textEncoder.encode(`${r}:`)),e.enqueue(n)}else if(t instanceof ArrayBuffer){const n=new Uint8Array(t),r=n.byteLength;e.enqueue(this.textEncoder.encode(`${r}:`)),e.enqueue(n)}else if(Array.isArray(t)){e.enqueue(A);for(let n of t)this.encode(n,e);e.enqueue(E)}else if(t instanceof Map){e.enqueue(v);const n=h(t.keys(),((t,e)=>(t="string"==typeof t?t:this.textDecoder.decode(t))<(e="string"==typeof e?e:this.textDecoder.decode(e))?-1:t>e?1:0));for(const r of n){const n=t.get(r);if(void 0!==n&&null!==t){if(this.path.push(r),this.encode(r,e),this.hooks){const t=this.hooks.get(this.path);if(t){const r=S(e,t);this.encode(n,r),t({value:void 0,done:!0})}else this.encode(n,e)}this.path.pop()}}e.enqueue(E)}else{e.enqueue(v);const n=Object.keys(t).sort();for(const r of n){const n=t[r];if(void 0!==n&&null!==t){if(this.path.push(r),this.encode(r,e),this.hooks){const t=this.hooks.get(this.path);if(t){const r=S(e,t);this.encode(n,r),t({value:void 0,done:!0})}else this.encode(n,e)}this.path.pop()}}e.enqueue(E)}}}function U(t,e){return new ReadableStream(new R(t,e))}function S(t,e){return new Proxy(t,{get:function(t,n,r){return"enqueue"!==n?Reflect.get(t,n,r):(n=>{t.enqueue(n),void 0!==n&&e({value:n,done:!1})}).bind(t)}})}function B(){const t={controller:null};return[new ReadableStream({start(e){t.controller=e}}),({value:e,done:n})=>{null!==t.controller&&(n?t.controller.close():t.controller.enqueue(e))}]}function T(){const[t,e]=B();return[new Response(t).arrayBuffer(),e]}function k(){const[t,e]=B();return[new Response(t).text(),e]}var L;!function(t){t.Integer="Integer",t.ByteString="ByteString",t.ListStart="ListStart",t.ListEnd="ListEnd",t.DictionaryStart="DictionaryStart",t.DictionaryEnd="DictionaryEnd"}(L||(L={}));const F=A[0],C=v[0],I=E[0];class x{endStack=[];token=null;byteStringLength=0;byteStringOffset=0;transform(t,e){this.tokenize(t,e)}flush(){if(this.endStack.length||this.token||this.byteStringLength||this.byteStringOffset)throw new SyntaxError("Incomplete stream")}tokenize(t,e){if(0!==t.byteLength)if(null===this.token&&0===this.byteStringLength){const n=t[0];if(105===n)this.token={type:L.Integer,value:new Uint8Array};else if(D(n))this.byteStringLength=n-48;else if(n===F)this.endStack.push(L.ListEnd),e.enqueue({type:L.ListStart});else if(n===C)this.endStack.push(L.DictionaryEnd),e.enqueue({type:L.DictionaryStart});else{if(n!==I)throw new SyntaxError(`Unexpected byte: ${n}`);{const t=this.endStack.pop();if(!t)throw new SyntaxError("Unbalanced delimiter");e.enqueue({type:t})}}this.tokenize(t.subarray(1),e)}else if(this.token&&0===this.byteStringLength)if(this.token.type===L.Integer){const n=t.indexOf(I);-1===n?this.token.value=this.token.value?z(this.token.value,t):t:(this.token.value=this.token.value?z(this.token.value,t.subarray(0,n)):t.subarray(0,n),e.enqueue(this.token),this.token=null,this.tokenize(t.subarray(n+1),e))}else{if(this.token.type!==L.ByteString)throw new Error("This is a bug");{const n=this.token.value.byteLength-this.byteStringOffset,r=t.byteLength;r<n?(this.token.value.set(t,this.byteStringOffset),this.byteStringOffset+=r):(this.token.value.set(t.subarray(0,n),this.byteStringOffset),this.byteStringOffset=0,e.enqueue(this.token),this.token=null,this.tokenize(t.subarray(n),e))}}else{if(!this.byteStringLength||null!==this.token)throw new Error("This is a bug");{let n=-1;for(const[e,r]of t.entries()){if(!D(r)){if(58===r){n=e;break}throw new SyntaxError(`Unexpected byte: ${r}`)}this.byteStringLength=10*this.byteStringLength-48+r}-1!==n&&(this.token={type:L.ByteString,value:new Uint8Array(this.byteStringLength)},this.byteStringLength=0,this.tokenize(t.subarray(n+1),e))}}}}function M(){return new TransformStream(new x)}async function H(t){let e;const n=[],r=t.getReader();let o;for(;;){const{done:t,value:i}=await r.read();if(t)break;const s=n.at(-1);if(s)if(Array.isArray(s))switch(i.type){case L.Integer:s.push(P(i.value));break;case L.ByteString:s.push(N(i.value));break;case L.DictionaryStart:{const t=Object.create(null);s.push(t),n.push(t);break}case L.ListStart:{const t=[];s.push(t),n.push(t);break}case L.ListEnd:n.pop();break;default:throw new SyntaxError(`Unexpected token: ${i}`)}else if(void 0===o)switch(i.type){case L.ByteString:o=N(i.value);break;case L.DictionaryEnd:n.pop();break;default:throw new SyntaxError(`Unexpected token: ${i}`)}else{switch(i.type){case L.Integer:s[o]=P(i.value);break;case L.ByteString:s[o]=N(i.value);break;case L.DictionaryStart:{const t=Object.create(null);s[o]=t,n.push(t);break}case L.ListStart:{const t=[];s[o]=t,n.push(t);break}default:throw new SyntaxError(`Unexpected token: ${i}`)}o=void 0}else{if(void 0!==e)throw new SyntaxError(`Unexpected token: ${i}`);switch(i.type){case L.Integer:e=P(i.value);break;case L.ByteString:e=N(i.value);break;case L.DictionaryStart:{const t=Object.create(null);n.push(t),e=t;break}case L.ListStart:{const t=[];n.push(t),e=t;break}default:throw new SyntaxError(`Unexpected token: ${i}`)}}}if(n.length)throw new Error("Unexpected end of token stream");return e}async function Y(t){const e=M(),n=t.pipeThrough(e);return await H(n)}function P(t){let e=0,n=!0;for(const[r,o]of t.entries()){if(0===r&&45===o){n=!1;continue}if(1===r&&!n&&48===o)throw new SyntaxError("Negative zero is not a valid integer");if(1===r&&0===e)throw new SyntaxError("Leading zeros are not allowed");if(!D(o))throw new SyntaxError(`Unexpected byte: ${o}`);const t=o-48;(n&&"number"==typeof e&&e>(Number.MAX_SAFE_INTEGER-t)/10||!n&&"number"==typeof e&&e<(Number.MIN_SAFE_INTEGER+t)/10)&&(e=BigInt(e)),e="number"==typeof e?n?10*e+t:10*e-t:n?10n*e+BigInt(t):10n*e-BigInt(t)}return e}function N(t){return(new TextDecoder).decode(t)}function D(t){return t>=48&&t<=57}function z(...t){const e=new Uint8Array(t.reduce(((t,e)=>t+e.byteLength),0));return t.reduce(((t,n)=>(e.set(n,t),t+n.byteLength)),0),e}n(913);class q extends Error{constructor(t,e){super(((t,...e)=>{let n=t;return e.length>0&&(n+=` :: ${JSON.stringify(e)}`),n})(t,e)),this.name=t,this.details=e}}class O{constructor(){this.promise=new Promise(((t,e)=>{this.resolve=t,this.reject=e}))}}function _(t){const e=t.map((t=>Promise.resolve(t).then((t=>function(t){if(t instanceof Response){if(t.body)return t.body.getReader();throw new q("opaque-streams-source",{type:t.type})}return t instanceof ReadableStream?t.getReader():new Response(t).body.getReader()}(t))))),n=new O;let r=0;const o=new ReadableStream({pull(t){return e[r].then((t=>t.read())).then((o=>{if(o.done)return r++,r>=e.length?(t.close(),void n.resolve()):this.pull(t);t.enqueue(o.value)})).catch((t=>{throw n.reject(t),t}))},cancel(){n.resolve()}});return{done:n.promise,stream:o}}var K;n(1),function(t){t.V1="v1",t.V2="v2",t.HYBRID="hybrid"}(K||(K={}));const $=16384;var V;!function(t){t[t["16KB"]=16384]="16KB",t[t["32KB"]=32768]="32KB",t[t["64KB"]=65536]="64KB",t[t["128KB"]=131072]="128KB",t[t["256KB"]=262144]="256KB",t[t["512KB"]=524288]="512KB",t[t["1MB"]=1048576]="1MB",t[t["2MB"]=2097152]="2MB",t[t["4MB"]=4194304]="4MB",t[t["8MB"]=8388608]="8MB",t[t["16MB"]=16777216]="16MB",t[t["32MB"]=33554432]="32MB"}(V||(V={}));const X=new Uint8Array(32),j={type:K.V1,addCreatedBy:!0,addCreationDate:!0,addPaddingFiles:!1,blockLength:$,sortFiles:!0,isPrivate:!1},G={type:K.V2,addCreatedBy:!0,addCreationDate:!0,blockLength:$,metaVersion:2,isPrivate:!1},W={type:K.HYBRID,addCreatedBy:!0,addCreationDate:!0,blockLength:$,metaVersion:2,isPrivate:!1};async function Z(t,e={type:K.V1},r=((t,e)=>{})){if(0===t.length)throw new Error("empty file list");let o;switch(e.type){case K.V1:o={...j,...e};break;case K.V2:o={...G,...e};break;case K.HYBRID:o={...W,...e}}o.pieceLength??=w(t.reduce(((t,e)=>t+e.size),0),o.blockLength);let{addCreatedBy:i,addCreationDate:s,blockLength:u,comment:a,isPrivate:h,name:m,pieceLength:b}=o;if(o.type!==K.V1&&b<u)throw new Error(`piece length ${b} is smaller than block length ${u}`);if(0!=(b&b-1))throw new Error(`piece length ${b} is not a power of 2`);const A=b/u;o.announceList=p(o.announceList),void 0===o.announce&&void 0!==o.announceList&&(o.announce=o.announceList[0][0]);const{announce:v,announceList:E}=o,R={...v&&{announce:v},...E&&{"announce-list":E},...a&&{comment:a},...i&&{"created by":"torrefy v2.0.2"},...s&&{"creation date":Date.now()/1e3>>0}};let U,S,B=0,T=t.reduce(((t,e)=>t+Math.ceil(e.size/b)),0);if(o.type===K.V1){const{addPaddingFiles:e,sortFiles:n}=o;let r,i;if(n){const{fileTree:e,fileNodeMap:n,commonDir:r}=c(t);t=[...e].map((t=>n.get(t))),i=r}else i=d(t);if(o.name=m=g(m,i,t),e){const e=t.length-1;r=_(t.map((async(t,n)=>L(t.stream(),{padding:n!==e})))).stream,t=y(t,b,i)}else{T=Math.ceil(t.reduce(((t,e)=>t+e.size),0)/b);const{stream:e}=_(t.map((t=>Promise.resolve(t.stream()))));r=L(e)}U={...R,info:{...t.length>1?{files:t.map((t=>{const e=(t.webkitRelativePath||t.name).split("/");return void 0!==i&&e.shift(),{...t.padding&&{attr:"p"},length:t.size,path:e}}))}:{length:t[0].size},name:m,"piece length":b,pieces:await new Response(r).arrayBuffer(),...h&&{private:1}}}}else if(o.type===K.V2){const{metaVersion:e}=o,{fileTree:n,fileNodeMap:r,commonDir:i}=c(t),s=[...n];t=s.map((t=>r.get(t)));const u=new Map;o.name=m=g(m,i,t),await Promise.all(s.map((async(e,n)=>{const r=t[n];await k(e,r,r.stream(),u)}))),U={...R,info:{"file tree":n,"meta version":e,name:m,"piece length":b,...h&&{private:1}},...u.size>0&&{"piece layers":u}}}else{if(o.type!==K.HYBRID)throw new Error("torrent type is not supported");{const{metaVersion:e}=o,{fileTree:n,fileNodeMap:r,commonDir:i}=c(t),s=[...n];t=s.map((t=>r.get(t)));const u=new Map;o.name=m=g(m,i,t),T*=2;const a=t.length-1,f=[];await Promise.all(s.map((async(e,n)=>{const r=t[n],[o,i]=r.stream().tee();f.push(Promise.resolve(L(o,{padding:n!==a}))),await k(e,r,i,u)})));const l=_(f).stream;t=y(t,b,i),U={...R,info:{"file tree":n,...t.length>1?{files:t.map((t=>{const e=(t.webkitRelativePath||t.name).split("/");return void 0!==i&&e.shift(),{...t.padding&&{attr:"p"},length:t.size,path:e}}))}:{length:t[0].size},"meta version":e,name:m,"piece length":b,pieces:await new Response(l).arrayBuffer(),...h&&{private:1}},...u.size>0&&{"piece layers":u}}}}return U;async function k(t,e,r,o){const[i,s]=function(t){const e=t.pipeThrough(F(u)).pipeThrough(function(){let t=0,e=[];return new TransformStream({transform:async(r,o)=>{let i;++t;try{i=new Uint8Array(await crypto.subtle.digest("SHA-256",r))}catch{const{default:t}=await Promise.resolve().then(n.bind(n,673)),e=new t("SHA-256","UINT8ARRAY");e.update(r),i=e.getHash("UINT8ARRAY")}e.push(i),e.length===A&&(o.enqueue(e),e=[])},flush:async n=>{if(0===t)return;let r=0;if(t<A)r=l(t)-t;else{const e=t%A;e>0&&(r=A-e)}if(r>0)for(let t=0;t<r;++t)e.push(X);e.length>0&&n.enqueue(e)}})}()).pipeThrough(C(!0)),[r,o]=e.tee();return[o.pipeThrough(I()).pipeThrough(C()),r]}(r),a=new Response(i).arrayBuffer();if(e.size>b){const t=new Response(s).arrayBuffer();o.set(await a,await t)}e.size>0&&(t[""]["pieces root"]=await a)}function L(t,e={padding:!1}){return t.pipeThrough(F(b,{padding:e.padding})).pipeThrough(function(t=!1){return new TransformStream({transform:async(e,o)=>{let i;try{i=new Uint8Array(await crypto.subtle.digest("SHA-1",e))}catch{const{default:t}=await Promise.resolve().then(n.bind(n,211)),r=new t("SHA-1","UINT8ARRAY");r.update(e),i=r.getHash("UINT8ARRAY")}o.enqueue(i),t&&r(++B,T)}})}(!0))}function F(t,e={padding:!1}){let n=new Uint8Array(t),r=0;return new TransformStream({transform:(e,o)=>{for(;r+e.length>=t;){const i=t-r;n.set(e.subarray(0,i),r),r=0,o.enqueue(new Uint8Array(n)),e=e.subarray(i)}n.set(e,r),r+=e.length},flush:o=>{r>0&&(e.padding?(n.set(new Uint8Array(t-r),r),o.enqueue(n)):o.enqueue(n.subarray(0,r)))}})}function C(t=!1){return new TransformStream({transform:async(e,n)=>{n.enqueue(await f(e)),t&&r(++B,T)}})}function I(){let t=0,e=[];return new TransformStream({transform:n=>{++t,e.push(n)},flush:async n=>{const r=l(t)-t;if(r>0){S??=await f(Array(A).fill(new Uint8Array(32)));for(let t=0;t<r;++t)e.push(S)}n.enqueue(e)}})}}})(),r})()));
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.torrefy=t():e.torrefy=t()}(self,(()=>(()=>{"use strict";var e={913:()=>{try{self["workbox:core:6.5.3"]&&_()}catch(e){}},1:()=>{try{self["workbox:streams:6.5.3"]&&_()}catch(e){}},211:(e,t,n)=>{n.r(t),n.d(t,{default:()=>w});const r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function i(e,t,n,r){let i,o,s;const a=t||[0],u=(n=n||0)>>>3,c=-1===r?3:0;for(i=0;i<e.length;i+=1)s=i+u,o=s>>>2,a.length<=o&&a.push(0),a[o]|=e[i]<<8*(c+r*(s%4));return{value:a,binLen:8*e.length+n}}function o(e,t,n){switch(t){case"UTF8":case"UTF16BE":case"UTF16LE":break;default:throw new Error("encoding must be UTF8, UTF16BE, or UTF16LE")}switch(e){case"HEX":return function(e,t,r){return function(e,t,n,r){let i,o,s,a;if(0!=e.length%2)throw new Error("String of HEX type must be in byte increments");const u=t||[0],c=(n=n||0)>>>3,h=-1===r?3:0;for(i=0;i<e.length;i+=2){if(o=parseInt(e.substr(i,2),16),isNaN(o))throw new Error("String of HEX type contains invalid characters");for(a=(i>>>1)+c,s=a>>>2;u.length<=s;)u.push(0);u[s]|=o<<8*(h+r*(a%4))}return{value:u,binLen:4*e.length+n}}(e,t,r,n)};case"TEXT":return function(e,r,i){return function(e,t,n,r,i){let o,s,a,u,c,h,l,f,p=0;const d=n||[0],g=(r=r||0)>>>3;if("UTF8"===t)for(l=-1===i?3:0,a=0;a<e.length;a+=1)for(o=e.charCodeAt(a),s=[],128>o?s.push(o):2048>o?(s.push(192|o>>>6),s.push(128|63&o)):55296>o||57344<=o?s.push(224|o>>>12,128|o>>>6&63,128|63&o):(a+=1,o=65536+((1023&o)<<10|1023&e.charCodeAt(a)),s.push(240|o>>>18,128|o>>>12&63,128|o>>>6&63,128|63&o)),u=0;u<s.length;u+=1){for(h=p+g,c=h>>>2;d.length<=c;)d.push(0);d[c]|=s[u]<<8*(l+i*(h%4)),p+=1}else for(l=-1===i?2:0,f="UTF16LE"===t&&1!==i||"UTF16LE"!==t&&1===i,a=0;a<e.length;a+=1){for(o=e.charCodeAt(a),!0===f&&(u=255&o,o=u<<8|o>>>8),h=p+g,c=h>>>2;d.length<=c;)d.push(0);d[c]|=o<<8*(l+i*(h%4)),p+=2}return{value:d,binLen:8*p+r}}(e,t,r,i,n)};case"B64":return function(e,t,i){return function(e,t,n,i){let o,s,a,u,c,h,l,f=0;const p=t||[0],d=(n=n||0)>>>3,g=-1===i?3:0,w=e.indexOf("=");if(-1===e.search(/^[a-zA-Z0-9=+/]+$/))throw new Error("Invalid character in base-64 string");if(e=e.replace(/=/g,""),-1!==w&&w<e.length)throw new Error("Invalid '=' found in base-64 string");for(s=0;s<e.length;s+=4){for(c=e.substr(s,4),u=0,a=0;a<c.length;a+=1)o=r.indexOf(c.charAt(a)),u|=o<<18-6*a;for(a=0;a<c.length-1;a+=1){for(l=f+d,h=l>>>2;p.length<=h;)p.push(0);p[h]|=(u>>>16-8*a&255)<<8*(g+i*(l%4)),f+=1}}return{value:p,binLen:8*f+n}}(e,t,i,n)};case"BYTES":return function(e,t,r){return function(e,t,n,r){let i,o,s,a;const u=t||[0],c=(n=n||0)>>>3,h=-1===r?3:0;for(o=0;o<e.length;o+=1)i=e.charCodeAt(o),a=o+c,s=a>>>2,u.length<=s&&u.push(0),u[s]|=i<<8*(h+r*(a%4));return{value:u,binLen:8*e.length+n}}(e,t,r,n)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(e){throw new Error("ARRAYBUFFER not supported by this environment")}return function(e,t,r){return function(e,t,n,r){return i(new Uint8Array(e),t,n,r)}(e,t,r,n)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(e){throw new Error("UINT8ARRAY not supported by this environment")}return function(e,t,r){return i(e,t,r,n)};default:throw new Error("format must be HEX, TEXT, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}function s(e,t,n,i){switch(e){case"HEX":return function(e){return function(e,t,n,r){const i="0123456789abcdef";let o,s,a="";const u=t/8,c=-1===n?3:0;for(o=0;o<u;o+=1)s=e[o>>>2]>>>8*(c+n*(o%4)),a+=i.charAt(s>>>4&15)+i.charAt(15&s);return r.outputUpper?a.toUpperCase():a}(e,t,n,i)};case"B64":return function(e){return function(e,t,n,i){let o,s,a,u,c,h="";const l=t/8,f=-1===n?3:0;for(o=0;o<l;o+=3)for(u=o+1<l?e[o+1>>>2]:0,c=o+2<l?e[o+2>>>2]:0,a=(e[o>>>2]>>>8*(f+n*(o%4))&255)<<16|(u>>>8*(f+n*((o+1)%4))&255)<<8|c>>>8*(f+n*((o+2)%4))&255,s=0;s<4;s+=1)h+=8*o+6*s<=t?r.charAt(a>>>6*(3-s)&63):i.b64Pad;return h}(e,t,n,i)};case"BYTES":return function(e){return function(e,t,n){let r,i,o="";const s=t/8,a=-1===n?3:0;for(r=0;r<s;r+=1)i=e[r>>>2]>>>8*(a+n*(r%4))&255,o+=String.fromCharCode(i);return o}(e,t,n)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(e){throw new Error("ARRAYBUFFER not supported by this environment")}return function(e){return function(e,t,n){let r;const i=t/8,o=new ArrayBuffer(i),s=new Uint8Array(o),a=-1===n?3:0;for(r=0;r<i;r+=1)s[r]=e[r>>>2]>>>8*(a+n*(r%4))&255;return o}(e,t,n)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(e){throw new Error("UINT8ARRAY not supported by this environment")}return function(e){return function(e,t,n){let r;const i=t/8,o=-1===n?3:0,s=new Uint8Array(i);for(r=0;r<i;r+=1)s[r]=e[r>>>2]>>>8*(o+n*(r%4))&255;return s}(e,t,n)};default:throw new Error("format must be HEX, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}function a(e){const t={outputUpper:!1,b64Pad:"=",outputLen:-1},n=e||{},r="Output length must be a multiple of 8";if(t.outputUpper=n.outputUpper||!1,n.b64Pad&&(t.b64Pad=n.b64Pad),n.outputLen){if(n.outputLen%8!=0)throw new Error(r);t.outputLen=n.outputLen}else if(n.shakeLen){if(n.shakeLen%8!=0)throw new Error(r);t.outputLen=n.shakeLen}if("boolean"!=typeof t.outputUpper)throw new Error("Invalid outputUpper formatting option");if("string"!=typeof t.b64Pad)throw new Error("Invalid b64Pad formatting option");return t}function u(e,t){return e<<t|e>>>32-t}function c(e,t,n){return e^t^n}function h(e,t,n){return e&t^e&n^t&n}function l(e,t){const n=(65535&e)+(65535&t);return(65535&(e>>>16)+(t>>>16)+(n>>>16))<<16|65535&n}function f(e,t,n,r,i){const o=(65535&e)+(65535&t)+(65535&n)+(65535&r)+(65535&i);return(65535&(e>>>16)+(t>>>16)+(n>>>16)+(r>>>16)+(i>>>16)+(o>>>16))<<16|65535&o}function p(e){return[1732584193,4023233417,2562383102,271733878,3285377520]}function d(e,t){let n,r,i,o,s,a,p;const d=[];for(n=t[0],r=t[1],i=t[2],o=t[3],s=t[4],p=0;p<80;p+=1)d[p]=p<16?e[p]:u(d[p-3]^d[p-8]^d[p-14]^d[p-16],1),a=p<20?f(u(n,5),(g=r)&i^~g&o,s,1518500249,d[p]):p<40?f(u(n,5),c(r,i,o),s,1859775393,d[p]):p<60?f(u(n,5),h(r,i,o),s,2400959708,d[p]):f(u(n,5),c(r,i,o),s,3395469782,d[p]),s=o,o=i,i=u(r,30),r=n,n=a;var g;return t[0]=l(n,t[0]),t[1]=l(r,t[1]),t[2]=l(i,t[2]),t[3]=l(o,t[3]),t[4]=l(s,t[4]),t}function g(e,t,n,r){let i;const o=15+(t+65>>>9<<4),s=t+n;for(;e.length<=o;)e.push(0);for(e[t>>>5]|=128<<24-t%32,e[o]=4294967295&s,e[o-1]=s/4294967296|0,i=0;i<e.length;i+=16)r=d(e.slice(i,i+16),r);return r}class w extends class{constructor(e,t,n){const r=n||{};if(this.t=t,this.i=r.encoding||"UTF8",this.numRounds=r.numRounds||1,isNaN(this.numRounds)||this.numRounds!==parseInt(this.numRounds,10)||1>this.numRounds)throw new Error("numRounds must a integer >= 1");this.o=e,this.h=[],this.u=0,this.l=!1,this.A=0,this.p=!1,this.R=[],this.U=[]}update(e){let t,n=0;const r=this.T>>>5,i=this.F(e,this.h,this.u),o=i.binLen,s=i.value,a=o>>>5;for(t=0;t<a;t+=r)n+this.T<=o&&(this.m=this.g(s.slice(t,t+r),this.m),n+=this.T);return this.A+=n,this.h=s.slice(n>>>5),this.u=o%this.T,this.l=!0,this}getHash(e,t){let n,r,i=this.B;const o=a(t);if(this.v){if(-1===o.outputLen)throw new Error("Output length must be specified in options");i=o.outputLen}const u=s(e,i,this.Y,o);if(this.p&&this.H)return u(this.H(o));for(r=this.C(this.h.slice(),this.u,this.A,this.I(this.m),i),n=1;n<this.numRounds;n+=1)this.v&&i%32!=0&&(r[r.length-1]&=16777215>>>24-i%32),r=this.C(r,i,0,this.L(this.o),i);return u(r)}setHMACKey(e,t,n){if(!this.M)throw new Error("Variant does not support HMAC");if(this.l)throw new Error("Cannot set MAC key after calling update");const r=o(t,(n||{}).encoding||"UTF8",this.Y);this.N(r(e))}N(e){const t=this.T>>>3,n=t/4-1;let r;if(1!==this.numRounds)throw new Error("Cannot set numRounds with MAC");if(this.p)throw new Error("MAC key already set");for(t<e.binLen/8&&(e.value=this.C(e.value,e.binLen,0,this.L(this.o),this.B));e.value.length<=n;)e.value.push(0);for(r=0;r<=n;r+=1)this.R[r]=909522486^e.value[r],this.U[r]=1549556828^e.value[r];this.m=this.g(this.R,this.m),this.A=this.T,this.p=!0}getHMAC(e,t){const n=a(t);return s(e,this.B,this.Y,n)(this.S())}S(){let e;if(!this.p)throw new Error("Cannot call getHMAC without first setting MAC key");const t=this.C(this.h.slice(),this.u,this.A,this.I(this.m),this.B);return e=this.g(this.U,this.L(this.o)),e=this.C(t,this.B,this.T,e,this.B),e}}{constructor(e,t,n){if("SHA-1"!==e)throw new Error("Chosen SHA variant is not supported");super(e,t,n);const r=n||{};this.M=!0,this.H=this.S,this.Y=-1,this.F=o(this.t,this.i,this.Y),this.g=d,this.I=function(e){return e.slice()},this.L=p,this.C=g,this.m=[1732584193,4023233417,2562383102,271733878,3285377520],this.T=512,this.B=160,this.v=!1,r.hmacKey&&this.N(function(e,t,n,r){const i="hmacKey must include a value and format";if(!t)throw new Error(i);if(void 0===t.value||!t.format)throw new Error(i);return o(t.format,t.encoding||"UTF8",n)(t.value)}(0,r.hmacKey,this.Y))}}},673:(e,t,n)=>{n.r(t),n.d(t,{default:()=>A});const r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function i(e,t,n,r){let i,o,s;const a=t||[0],u=(n=n||0)>>>3,c=-1===r?3:0;for(i=0;i<e.length;i+=1)s=i+u,o=s>>>2,a.length<=o&&a.push(0),a[o]|=e[i]<<8*(c+r*(s%4));return{value:a,binLen:8*e.length+n}}function o(e,t,n){switch(t){case"UTF8":case"UTF16BE":case"UTF16LE":break;default:throw new Error("encoding must be UTF8, UTF16BE, or UTF16LE")}switch(e){case"HEX":return function(e,t,r){return function(e,t,n,r){let i,o,s,a;if(0!=e.length%2)throw new Error("String of HEX type must be in byte increments");const u=t||[0],c=(n=n||0)>>>3,h=-1===r?3:0;for(i=0;i<e.length;i+=2){if(o=parseInt(e.substr(i,2),16),isNaN(o))throw new Error("String of HEX type contains invalid characters");for(a=(i>>>1)+c,s=a>>>2;u.length<=s;)u.push(0);u[s]|=o<<8*(h+r*(a%4))}return{value:u,binLen:4*e.length+n}}(e,t,r,n)};case"TEXT":return function(e,r,i){return function(e,t,n,r,i){let o,s,a,u,c,h,l,f,p=0;const d=n||[0],g=(r=r||0)>>>3;if("UTF8"===t)for(l=-1===i?3:0,a=0;a<e.length;a+=1)for(o=e.charCodeAt(a),s=[],128>o?s.push(o):2048>o?(s.push(192|o>>>6),s.push(128|63&o)):55296>o||57344<=o?s.push(224|o>>>12,128|o>>>6&63,128|63&o):(a+=1,o=65536+((1023&o)<<10|1023&e.charCodeAt(a)),s.push(240|o>>>18,128|o>>>12&63,128|o>>>6&63,128|63&o)),u=0;u<s.length;u+=1){for(h=p+g,c=h>>>2;d.length<=c;)d.push(0);d[c]|=s[u]<<8*(l+i*(h%4)),p+=1}else for(l=-1===i?2:0,f="UTF16LE"===t&&1!==i||"UTF16LE"!==t&&1===i,a=0;a<e.length;a+=1){for(o=e.charCodeAt(a),!0===f&&(u=255&o,o=u<<8|o>>>8),h=p+g,c=h>>>2;d.length<=c;)d.push(0);d[c]|=o<<8*(l+i*(h%4)),p+=2}return{value:d,binLen:8*p+r}}(e,t,r,i,n)};case"B64":return function(e,t,i){return function(e,t,n,i){let o,s,a,u,c,h,l,f=0;const p=t||[0],d=(n=n||0)>>>3,g=-1===i?3:0,w=e.indexOf("=");if(-1===e.search(/^[a-zA-Z0-9=+/]+$/))throw new Error("Invalid character in base-64 string");if(e=e.replace(/=/g,""),-1!==w&&w<e.length)throw new Error("Invalid '=' found in base-64 string");for(s=0;s<e.length;s+=4){for(c=e.substr(s,4),u=0,a=0;a<c.length;a+=1)o=r.indexOf(c.charAt(a)),u|=o<<18-6*a;for(a=0;a<c.length-1;a+=1){for(l=f+d,h=l>>>2;p.length<=h;)p.push(0);p[h]|=(u>>>16-8*a&255)<<8*(g+i*(l%4)),f+=1}}return{value:p,binLen:8*f+n}}(e,t,i,n)};case"BYTES":return function(e,t,r){return function(e,t,n,r){let i,o,s,a;const u=t||[0],c=(n=n||0)>>>3,h=-1===r?3:0;for(o=0;o<e.length;o+=1)i=e.charCodeAt(o),a=o+c,s=a>>>2,u.length<=s&&u.push(0),u[s]|=i<<8*(h+r*(a%4));return{value:u,binLen:8*e.length+n}}(e,t,r,n)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(e){throw new Error("ARRAYBUFFER not supported by this environment")}return function(e,t,r){return function(e,t,n,r){return i(new Uint8Array(e),t,n,r)}(e,t,r,n)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(e){throw new Error("UINT8ARRAY not supported by this environment")}return function(e,t,r){return i(e,t,r,n)};default:throw new Error("format must be HEX, TEXT, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}function s(e,t,n,i){switch(e){case"HEX":return function(e){return function(e,t,n,r){const i="0123456789abcdef";let o,s,a="";const u=t/8,c=-1===n?3:0;for(o=0;o<u;o+=1)s=e[o>>>2]>>>8*(c+n*(o%4)),a+=i.charAt(s>>>4&15)+i.charAt(15&s);return r.outputUpper?a.toUpperCase():a}(e,t,n,i)};case"B64":return function(e){return function(e,t,n,i){let o,s,a,u,c,h="";const l=t/8,f=-1===n?3:0;for(o=0;o<l;o+=3)for(u=o+1<l?e[o+1>>>2]:0,c=o+2<l?e[o+2>>>2]:0,a=(e[o>>>2]>>>8*(f+n*(o%4))&255)<<16|(u>>>8*(f+n*((o+1)%4))&255)<<8|c>>>8*(f+n*((o+2)%4))&255,s=0;s<4;s+=1)h+=8*o+6*s<=t?r.charAt(a>>>6*(3-s)&63):i.b64Pad;return h}(e,t,n,i)};case"BYTES":return function(e){return function(e,t,n){let r,i,o="";const s=t/8,a=-1===n?3:0;for(r=0;r<s;r+=1)i=e[r>>>2]>>>8*(a+n*(r%4))&255,o+=String.fromCharCode(i);return o}(e,t,n)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(e){throw new Error("ARRAYBUFFER not supported by this environment")}return function(e){return function(e,t,n){let r;const i=t/8,o=new ArrayBuffer(i),s=new Uint8Array(o),a=-1===n?3:0;for(r=0;r<i;r+=1)s[r]=e[r>>>2]>>>8*(a+n*(r%4))&255;return o}(e,t,n)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(e){throw new Error("UINT8ARRAY not supported by this environment")}return function(e){return function(e,t,n){let r;const i=t/8,o=-1===n?3:0,s=new Uint8Array(i);for(r=0;r<i;r+=1)s[r]=e[r>>>2]>>>8*(o+n*(r%4))&255;return s}(e,t,n)};default:throw new Error("format must be HEX, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}const a=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],u=[3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428],c=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225];function h(e){const t={outputUpper:!1,b64Pad:"=",outputLen:-1},n=e||{},r="Output length must be a multiple of 8";if(t.outputUpper=n.outputUpper||!1,n.b64Pad&&(t.b64Pad=n.b64Pad),n.outputLen){if(n.outputLen%8!=0)throw new Error(r);t.outputLen=n.outputLen}else if(n.shakeLen){if(n.shakeLen%8!=0)throw new Error(r);t.outputLen=n.shakeLen}if("boolean"!=typeof t.outputUpper)throw new Error("Invalid outputUpper formatting option");if("string"!=typeof t.b64Pad)throw new Error("Invalid b64Pad formatting option");return t}function l(e,t){return e>>>t|e<<32-t}function f(e,t){return e>>>t}function p(e,t,n){return e&t^~e&n}function d(e,t,n){return e&t^e&n^t&n}function g(e){return l(e,2)^l(e,13)^l(e,22)}function w(e,t){const n=(65535&e)+(65535&t);return(65535&(e>>>16)+(t>>>16)+(n>>>16))<<16|65535&n}function y(e,t,n,r){const i=(65535&e)+(65535&t)+(65535&n)+(65535&r);return(65535&(e>>>16)+(t>>>16)+(n>>>16)+(r>>>16)+(i>>>16))<<16|65535&i}function m(e,t,n,r,i){const o=(65535&e)+(65535&t)+(65535&n)+(65535&r)+(65535&i);return(65535&(e>>>16)+(t>>>16)+(n>>>16)+(r>>>16)+(i>>>16)+(o>>>16))<<16|65535&o}function b(e){return l(e,7)^l(e,18)^f(e,3)}function v(e){return l(e,6)^l(e,11)^l(e,25)}function L(e){let t;return t="SHA-224"==e?u.slice():c.slice(),t}function k(e,t){let n,r,i,o,s,u,c,h,L,k,A;const E=[];for(n=t[0],r=t[1],i=t[2],o=t[3],s=t[4],u=t[5],c=t[6],h=t[7],A=0;A<64;A+=1)E[A]=A<16?e[A]:y(l(R=E[A-2],17)^l(R,19)^f(R,10),E[A-7],b(E[A-15]),E[A-16]),L=m(h,v(s),p(s,u,c),a[A],E[A]),k=w(g(n),d(n,r,i)),h=c,c=u,u=s,s=w(o,L),o=i,i=r,r=n,n=w(L,k);var R;return t[0]=w(n,t[0]),t[1]=w(r,t[1]),t[2]=w(i,t[2]),t[3]=w(o,t[3]),t[4]=w(s,t[4]),t[5]=w(u,t[5]),t[6]=w(c,t[6]),t[7]=w(h,t[7]),t}class A extends class{constructor(e,t,n){const r=n||{};if(this.t=t,this.i=r.encoding||"UTF8",this.numRounds=r.numRounds||1,isNaN(this.numRounds)||this.numRounds!==parseInt(this.numRounds,10)||1>this.numRounds)throw new Error("numRounds must a integer >= 1");this.o=e,this.h=[],this.u=0,this.A=!1,this.l=0,this.p=!1,this.R=[],this.U=[]}update(e){let t,n=0;const r=this.T>>>5,i=this.F(e,this.h,this.u),o=i.binLen,s=i.value,a=o>>>5;for(t=0;t<a;t+=r)n+this.T<=o&&(this.m=this.g(s.slice(t,t+r),this.m),n+=this.T);return this.l+=n,this.h=s.slice(n>>>5),this.u=o%this.T,this.A=!0,this}getHash(e,t){let n,r,i=this.B;const o=h(t);if(this.H){if(-1===o.outputLen)throw new Error("Output length must be specified in options");i=o.outputLen}const a=s(e,i,this.v,o);if(this.p&&this.Y)return a(this.Y(o));for(r=this.C(this.h.slice(),this.u,this.l,this.S(this.m),i),n=1;n<this.numRounds;n+=1)this.H&&i%32!=0&&(r[r.length-1]&=16777215>>>24-i%32),r=this.C(r,i,0,this.I(this.o),i);return a(r)}setHMACKey(e,t,n){if(!this.L)throw new Error("Variant does not support HMAC");if(this.A)throw new Error("Cannot set MAC key after calling update");const r=o(t,(n||{}).encoding||"UTF8",this.v);this.M(r(e))}M(e){const t=this.T>>>3,n=t/4-1;let r;if(1!==this.numRounds)throw new Error("Cannot set numRounds with MAC");if(this.p)throw new Error("MAC key already set");for(t<e.binLen/8&&(e.value=this.C(e.value,e.binLen,0,this.I(this.o),this.B));e.value.length<=n;)e.value.push(0);for(r=0;r<=n;r+=1)this.R[r]=909522486^e.value[r],this.U[r]=1549556828^e.value[r];this.m=this.g(this.R,this.m),this.l=this.T,this.p=!0}getHMAC(e,t){const n=h(t);return s(e,this.B,this.v,n)(this.N())}N(){let e;if(!this.p)throw new Error("Cannot call getHMAC without first setting MAC key");const t=this.C(this.h.slice(),this.u,this.l,this.S(this.m),this.B);return e=this.g(this.U,this.I(this.o)),e=this.C(t,this.B,this.T,e,this.B),e}}{constructor(e,t,n){if("SHA-224"!==e&&"SHA-256"!==e)throw new Error("Chosen SHA variant is not supported");super(e,t,n);const r=n||{};this.Y=this.N,this.L=!0,this.v=-1,this.F=o(this.t,this.i,this.v),this.g=k,this.S=function(e){return e.slice()},this.I=L,this.C=function(t,n,r,i){return function(e,t,n,r,i){let o,s;const a=15+(t+65>>>9<<4),u=t+n;for(;e.length<=a;)e.push(0);for(e[t>>>5]|=128<<24-t%32,e[a]=4294967295&u,e[a-1]=u/4294967296|0,o=0;o<e.length;o+=16)r=k(e.slice(o,o+16),r);return s="SHA-224"===i?[r[0],r[1],r[2],r[3],r[4],r[5],r[6]]:r,s}(t,n,r,i,e)},this.m=L(e),this.T=512,this.B="SHA-224"===e?224:256,this.H=!1,r.hmacKey&&this.M(function(e,t,n,r){const i="hmacKey must include a value and format";if(!t)throw new Error(i);if(void 0===t.value||!t.format)throw new Error(i);return o(t.format,t.encoding||"UTF8",n)(t.value)}(0,r.hmacKey,this.v))}}}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var o=t[r]={exports:{}};return e[r](o,o.exports,n),o.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};return(()=>{n.r(r),n.d(r,{BUFF_0:()=>g,BUFF_COLON:()=>l,BUFF_D:()=>o,BUFF_E:()=>a,BUFF_I:()=>c,BUFF_L:()=>t,BUFF_MINUS:()=>p,BYTE_0:()=>d,BYTE_COLON:()=>h,BYTE_D:()=>i,BYTE_E:()=>s,BYTE_I:()=>u,BYTE_L:()=>e,BYTE_MINUS:()=>f,BlockHasher:()=>q,ChunkSplitter:()=>$,CommonPieceLength:()=>Le,DEFAULT_BLOCK_LENGTH:()=>ve,MerkleRootCalculator:()=>K,MerkleTreeBalancer:()=>X,PieceHasher:()=>W,TokenType:()=>B,Tokenizer:()=>F,TorrentType:()=>be,compareEntryNames:()=>me,concatUint8Arrays:()=>b,create:()=>Ue,decode:()=>x,encode:()=>E,getEntriesOfDirEntry:()=>ne,getFileOfFileEntry:()=>re,getSortedIndex:()=>y,isDigitByte:()=>w,isFile:()=>J,isFileSystemDirectoryEntry:()=>G,isFileSystemDirectoryHandle:()=>Q,isFileSystemFileEntry:()=>Z,isFileSystemFileHandle:()=>ee,isFileTreeDirEntry:()=>ye,isFileTreeDirNode:()=>ge,isFileTreeFileEntry:()=>we,isFileTreeFileNode:()=>de,iterableSort:()=>m,merkleRoot:()=>L,nextPowerOfTwo:()=>v,packEntriesToDirNode:()=>fe,parse:()=>C,populateFileTree:()=>le,resolveCommonDirAndTorrentName:()=>he,useArrayBufferPromiseHook:()=>S,useTextPromiseHook:()=>T,useUint8ArrayStreamHook:()=>U});const e=108,t=new Uint8Array([e]),i=100,o=new Uint8Array([i]),s=101,a=new Uint8Array([s]),u=105,c=new Uint8Array([u]),h=58,l=new Uint8Array([h]),f=45,p=new Uint8Array([f]),d=48,g=new Uint8Array([d]);function w(e){return e>=d&&e<=d+9}function y(e,t,n){let r=0,i=e.length;for(;r<i;){const o=r+i>>>1,s=n(e[o],t);if(0===s)return{index:o,result:e[o]};s<0?r=o+1:i=o}return{index:r,result:void 0}}function m(e,t){const n=[];for(const r of e){const{index:e}=y(n,r,t);n.splice(e,0,r)}return n}function b(...e){const t=new Uint8Array(e.reduce(((e,t)=>e+t.byteLength),0));return e.reduce(((e,n)=>(t.set(n,e),e+n.byteLength)),0),t}function v(e){return 1<<32-Math.clz32(e-1)}async function L(e){if(0===e.length)throw new Error("Empty leaves");const t=new Uint8Array(64);for(;e.length>1;){let r=!1;const i=[];for(const o of e)if(r){let e;t.set(o,32);try{e=new Uint8Array(await crypto.subtle.digest("SHA-256",t))}catch{const{default:r}=await Promise.resolve().then(n.bind(n,673)),i=new r("SHA-256","UINT8ARRAY");i.update(t),e=i.getHash("UINT8ARRAY")}i.push(e),r=!1}else t.set(o),r=!0;e=i}return e[0]}const k=new WeakMap;class A{textEncoder=new TextEncoder;textDecoder=new TextDecoder;data;path=[];hooks;consumedHookHandler=new WeakMap;constructor(e,t){this.data=e,this.hooks=t,t&&k.set(t,!0)}start(e){if(this.encode(this.data,e),this.hooks)for(const e of this.hooks.values())this.consumedHookHandler.get(e)||e({value:void 0,done:!0});e.close()}encode(e,n){if(null!=e)if("boolean"==typeof e)this.encode(e?1:0,n);else if("number"==typeof e){const t=Math.round(e);n.enqueue(this.textEncoder.encode(`i${t}e`)),t!==e&&(console.warn(`WARNING: Possible data corruption detected with value "${e}":`,`Bencoding only defines support for integers, value was converted to "${t}"`),console.trace())}else if("bigint"==typeof e)n.enqueue(this.textEncoder.encode(`i${e}e`));else if("string"==typeof e){const t=this.textEncoder.encode(e),r=t.byteLength;n.enqueue(this.textEncoder.encode(`${r}:`)),n.enqueue(t)}else if(e instanceof ArrayBuffer){const t=new Uint8Array(e),r=t.byteLength;n.enqueue(this.textEncoder.encode(`${r}:`)),n.enqueue(t)}else if(Array.isArray(e)){n.enqueue(t);let r=0;for(const t of e){if(this.path.push(r),this.hooks){const e=this.hooks.get(this.path);if(e){const r=R(n,e);this.encode(t,r),e({value:void 0,done:!0})}else this.encode(t,n)}this.path.pop(),++r}n.enqueue(a)}else if(e instanceof Map){n.enqueue(o);const t=m(e.keys(),((e,t)=>(e="string"==typeof e?e:this.textDecoder.decode(e))<(t="string"==typeof t?t:this.textDecoder.decode(t))?-1:e>t?1:0));for(const r of t){const t=e.get(r);if(void 0!==t&&null!==e)if(r instanceof ArrayBuffer)this.encode(r,n),this.encode(t,n);else{if(this.path.push(r),this.encode(r,n),this.hooks){const e=this.hooks.get(this.path);if(e){const r=R(n,e);this.encode(t,r),e({value:void 0,done:!0}),this.consumedHookHandler.set(e,!0)}else this.encode(t,n)}this.path.pop()}}n.enqueue(a)}else{n.enqueue(o);const t=Object.keys(e).sort();for(const r of t){const t=e[r];if(void 0!==t&&null!==e){if(this.path.push(r),this.encode(r,n),this.hooks){const e=this.hooks.get(this.path);if(e){const r=R(n,e);this.encode(t,r),e({value:void 0,done:!0}),this.consumedHookHandler.set(e,!0)}else this.encode(t,n)}this.path.pop()}}n.enqueue(a)}}}function E(e,t){return new ReadableStream(new A(e,t))}function R(e,t){return new Proxy(e,{get:function(e,n,r){return"enqueue"===n?(n=>{e.enqueue(n),t({value:n,done:!1})}).bind(e):Reflect.get(e,n,r)}})}function U(e,t){const n={controller:null},r=new ReadableStream({start(e){n.controller=e},pull(e){k.get(t)||(console.warn("You need to call encode() first and then consume hooks."),e.close(),n.controller=null)}});return t.set(e,(({value:e,done:t})=>{null!==n.controller&&(t?n.controller.close():n.controller.enqueue(e))})),[r]}function S(e,t){const[n]=U(e,t);return[new Response(n).arrayBuffer()]}function T(e,t){const[n]=U(e,t);return[new Response(n).text()]}var B;!function(e){e.Integer="Integer",e.ByteString="ByteString",e.ListStart="ListStart",e.ListEnd="ListEnd",e.DictionaryStart="DictionaryStart",e.DictionaryEnd="DictionaryEnd",e.NewTokenType="NewTokenType"}(B||(B={}));class P{endStack=[];token=null;byteStringLength=-1;byteStringOffset=0;transform(e,t){this.tokenize(e,t)}flush(){if(this.endStack.length||this.token||-1!==this.byteStringLength||this.byteStringOffset)throw new SyntaxError("Unexpected end of torrent stream")}tokenize(t,n){if(0!==t.byteLength)if(null===this.token&&-1===this.byteStringLength){const r=t[0];if(r===u)this.token={type:B.Integer,value:new Uint8Array};else if(w(r))this.byteStringLength=r-d;else if(r===e)this.endStack.push(B.ListEnd),n.enqueue({type:B.ListStart});else if(r===i)this.endStack.push(B.DictionaryEnd),n.enqueue({type:B.DictionaryStart});else{if(r!==s)throw new SyntaxError(`Unexpected byte: ${r}`);{const e=this.endStack.pop();if(!e)throw new SyntaxError("Unbalanced delimiter");n.enqueue({type:e})}}this.tokenize(t.subarray(1),n)}else if(this.token&&-1===this.byteStringLength)if(this.token.type===B.Integer){const e=t.indexOf(s);-1===e?this.token.value=this.token.value?b(this.token.value,t):t:(this.token.value=this.token.value?b(this.token.value,t.subarray(0,e)):t.subarray(0,e),n.enqueue(this.token),this.token=null,this.tokenize(t.subarray(e+1),n))}else{if(this.token.type!==B.ByteString)throw new Error("This is a bug");{const e=this.token.value.byteLength-this.byteStringOffset,r=t.byteLength;r<e?(this.token.value.set(t,this.byteStringOffset),this.byteStringOffset+=r):(this.token.value.set(t.subarray(0,e),this.byteStringOffset),this.byteStringOffset=0,n.enqueue(this.token),this.token=null,this.tokenize(t.subarray(e),n))}}else{if(!(this.byteStringLength>-1&&null===this.token))throw new Error("This is a bug");{let e=-1;for(const[n,r]of t.entries()){if(!w(r)){if(r===h){e=n;break}throw new SyntaxError(`Unexpected byte: ${r}`)}this.byteStringLength=10*this.byteStringLength-d+r}-1!==e&&(this.token={type:B.ByteString,value:new Uint8Array(this.byteStringLength)},this.byteStringLength=-1,this.tokenize(t.subarray(e+1),n))}}}}class F extends TransformStream{constructor(){super(new P)}}async function C(e){let t;const n=[],r=e.getReader();let i;for(;;){const{done:e,value:o}=await r.read();if(e)break;const s=n.at(-1);if(s)if(Array.isArray(s))switch(o.type){case B.Integer:s.push(N(o.value));break;case B.ByteString:s.push(H(o.value));break;case B.DictionaryStart:{const e=Object.create(null);s.push(e),n.push(e);break}case B.ListStart:{const e=[];s.push(e),n.push(e);break}case B.ListEnd:n.pop();break;default:throw new SyntaxError(`Unexpected token: ${JSON.stringify(o)}`)}else if(void 0===i)switch(o.type){case B.ByteString:i=H(o.value);break;case B.DictionaryEnd:n.pop();break;default:throw new SyntaxError(`Unexpected token: ${JSON.stringify(o)}`)}else{switch(o.type){case B.Integer:s[i]=N(o.value);break;case B.ByteString:s[i]=H(o.value);break;case B.DictionaryStart:{const e=Object.create(null);s[i]=e,n.push(e);break}case B.ListStart:{const e=[];s[i]=e,n.push(e);break}default:throw new SyntaxError(`Unexpected token: ${JSON.stringify(o)}`)}i=void 0}else{if(void 0!==t)throw new SyntaxError(`Unexpected token: ${JSON.stringify(o)}`);switch(o.type){case B.Integer:t=N(o.value);break;case B.ByteString:t=H(o.value);break;case B.DictionaryStart:{const e=Object.create(null);n.push(e),t=e;break}case B.ListStart:{const e=[];n.push(e),t=e;break}default:throw new SyntaxError(`Unexpected token: ${JSON.stringify(o)}`)}}}if(n.length)throw new Error("Unexpected end of token stream");return t}async function x(e){const t=new F,n=e.pipeThrough(t);return await C(n)}function N(e){let t=0,n=!0;for(const[r,i]of e.entries()){if(0===r&&i===f){n=!1;continue}if(1===r&&!n&&i===d)throw new SyntaxError("Negative zero is not a valid integer");if(1===r&&0===t)throw new SyntaxError("Leading zeros are not allowed");if(!w(i))throw new SyntaxError(`Unexpected byte: ${i}`);const e=i-d;(n&&"number"==typeof t&&t>(Number.MAX_SAFE_INTEGER-e)/10||!n&&"number"==typeof t&&t<(Number.MIN_SAFE_INTEGER+e)/10)&&(t=BigInt(t)),t="number"==typeof t?n?10*t+e:10*t-e:n?10n*t+BigInt(e):10n*t-BigInt(e)}return t}function H(e){return(new TextDecoder).decode(e)}n(913);class I extends Error{constructor(e,t){super(((e,...t)=>{let n=e;return t.length>0&&(n+=` :: ${JSON.stringify(t)}`),n})(e,t)),this.name=e,this.details=t}}class M{constructor(){this.promise=new Promise(((e,t)=>{this.resolve=e,this.reject=t}))}}function Y(e){const t=e.map((e=>Promise.resolve(e).then((e=>function(e){if(e instanceof Response){if(e.body)return e.body.getReader();throw new I("opaque-streams-source",{type:e.type})}return e instanceof ReadableStream?e.getReader():new Response(e).body.getReader()}(e))))),n=new M;let r=0;const i=new ReadableStream({pull(e){return t[r].then((e=>e.read())).then((i=>{if(i.done)return r++,r>=t.length?(e.close(),void n.resolve()):this.pull(e);e.enqueue(i.value)})).catch((e=>{throw n.reject(e),e}))},cancel(){n.resolve()}});return{done:n.promise,stream:i}}n(1);const D=new Uint8Array(32);class O{blockCount=0;merkleLeaves=[];blocksPerPiece;constructor(e){this.blocksPerPiece=e}async transform(e,t){let r;++this.blockCount;try{r=new Uint8Array(await crypto.subtle.digest("SHA-256",e))}catch{const{default:t}=await Promise.resolve().then(n.bind(n,673)),i=new t("SHA-256","UINT8ARRAY");i.update(e),r=i.getHash("UINT8ARRAY")}this.merkleLeaves.push(r),this.merkleLeaves.length===this.blocksPerPiece&&(t.enqueue(this.merkleLeaves),this.merkleLeaves=[])}flush(e){if(0===this.blockCount)return;let t=0;if(this.blockCount<this.blocksPerPiece)t=v(this.blockCount)-this.blockCount;else{const e=this.blockCount%this.blocksPerPiece;e>0&&(t=this.blocksPerPiece-e)}if(t>0)for(let e=0;e<t;++e)this.merkleLeaves.push(D);this.merkleLeaves.length>0&&e.enqueue(this.merkleLeaves)}}class q extends TransformStream{constructor(e){super(new O(e))}}class z{residuePointer=0;chunkLength;residue;opts;constructor(e,t={padding:!1}){this.chunkLength=e,this.opts=t,this.residue=new Uint8Array(this.chunkLength)}transform(e,t){for(;this.residuePointer+e.byteLength>=this.chunkLength;){const n=this.chunkLength-this.residuePointer;this.residue.set(e.subarray(0,n),this.residuePointer),this.residuePointer=0,t.enqueue(new Uint8Array(this.residue)),e=e.subarray(n)}this.residue.set(e,this.residuePointer),this.residuePointer+=e.byteLength}flush(e){this.residuePointer<=0||(this.opts.padding?(this.residue.set(new Uint8Array(this.chunkLength-this.residuePointer),this.residuePointer),e.enqueue(this.residue)):e.enqueue(this.residue.subarray(0,this.residuePointer)))}}class $ extends TransformStream{constructor(e,t={padding:!1}){super(new z(e,t))}}class _{updateProgress;constructor(e){this.updateProgress=e}async transform(e,t){t.enqueue(await L(e)),this.updateProgress&&await this.updateProgress()}}class K extends TransformStream{constructor(e){super(new _(e))}}class j{leafCount=0;merkleLeaves=[];blocksPerPiece;constructor(e){this.blocksPerPiece=e}transform(e){++this.leafCount,this.merkleLeaves.push(e)}async flush(e){const t=v(this.leafCount)-this.leafCount;if(t>0){const e=await this.padLeafPromise;for(let n=0;n<t;++n)this.merkleLeaves.push(e)}e.enqueue(this.merkleLeaves)}get padLeafPromise(){return L(Array(this.blocksPerPiece).fill(new Uint8Array(32)))}}class X extends TransformStream{constructor(e){super(new j(e))}}class V{updateProgress;constructor(e){this.updateProgress=e}async transform(e,t){let r;try{r=new Uint8Array(await crypto.subtle.digest("SHA-1",e))}catch{const{default:t}=await Promise.resolve().then(n.bind(n,211)),i=new t("SHA-1","UINT8ARRAY");i.update(e),r=i.getHash("UINT8ARRAY")}t.enqueue(r),this.updateProgress&&await this.updateProgress()}}class W extends TransformStream{constructor(e){super(new V(e))}}function J(e){return e instanceof File}function G(e){return!Q(e)&&!J(e)&&e.isDirectory}function Z(e){return!Q(e)&&!J(e)&&e.isFile}function Q(e){try{if(e instanceof FileSystemHandle&&"directory"===e.kind)return!0}catch(e){}return!1}function ee(e){try{if(e instanceof FileSystemHandle&&"file"===e.kind)return!0}catch(e){}return!1}function te(e){return new Promise(((t,n)=>{e.readEntries(t,n)}))}async function*ne(e){const t=e.createReader();let n=[];do{n=await te(t);for(const e of n)yield e}while(n.length>0)}function re(e){return new Promise(((t,n)=>{e.file(t,n)}))}const ie={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};let oe;const se=new Uint8Array(16);function ae(){if(!oe&&(oe="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!oe))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return oe(se)}const ue=[];for(let e=0;e<256;++e)ue.push((e+256).toString(16).slice(1));const ce=function(e,t,n){if(ie.randomUUID&&!t&&!e)return ie.randomUUID();const r=(e=e||{}).random||(e.rng||ae)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(let e=0;e<16;++e)t[n+e]=r[e];return t}return function(e,t=0){return(ue[e[t+0]]+ue[e[t+1]]+ue[e[t+2]]+ue[e[t+3]]+"-"+ue[e[t+4]]+ue[e[t+5]]+"-"+ue[e[t+6]]+ue[e[t+7]]+"-"+ue[e[t+8]]+ue[e[t+9]]+"-"+ue[e[t+10]]+ue[e[t+11]]+ue[e[t+12]]+ue[e[t+13]]+ue[e[t+14]]+ue[e[t+15]]).toLowerCase()}(r)};function he(e,t){if(t.size>1||0===t.size)return{name:e??ce(),commonDir:void 0};const[n,r]=t.entries().next().value;return de(r)?{name:n,commonDir:void 0}:{name:e??n,commonDir:n}}async function le(e,{sort:t=!0,compareFunction:n=me,polyfillWebkitRelativePath:r=!0}={sort:!0,compareFunction:me,polyfillWebkitRelativePath:!0}){let i=0,o=0;const s=new WeakMap,a=new WeakMap,u=new WeakMap,c=["file tree",[]],h=[c];let l=!1;for await(const t of e)await f(t);return{fileTree:fe(c[1],l),traverseTree:function*e(t){if(ge(t))for(const n of t.values())yield*e(n);else yield[t,u.get(t)]},totalFileSize:i,totalFileCount:o};async function f(e){const p=h.at(-1);if(!p)throw new Error("This is a bug");const d=J(e),g=Q(e),w=G(e),m=ee(e),b=Z(e);if(g||w){const r=e.name,{index:i,result:o}=y(p[1],r,n);let s=o;if(we(s))throw new Error("A same name file already exists");if(ye(s)&&g){const t=a.get(s);if(!t||!await e.isSameEntry(t))throw new Error("File system handle not match")}s||(s=[r,[]],t?p[1].splice(i,0,s):p[1].push(s),g&&a.set(s,e)),h.push(s);for await(const t of g?e.values():ne(e))await f(t);s[1]=new Map(s[1]),h.pop()}else if(m||b){const a=e.name,{index:c,result:l}=y(p[1],a,n);let f=l;if(we(f)&&m){const t=s.get(f);if(!t||!await e.isSameEntry(t))throw new Error("A same name file already exists")}if(ye(f))throw new Error("A same name directory already exists");if(f)return;const d=await(m?e.getFile():re(e)),g=d.size;if(r){const e=h.reduce(((e,t,n)=>0===n?e:e+t[0]+"/"),"")+d.name;Object.defineProperty(d,"webkitRelativePath",{configurable:!0,enumerable:!0,get:()=>e})}const w={"":{length:g}};f=[a,w],t?p[1].splice(c,0,f):p[1].push(f),m&&s.set(f,e),u.set(w,d),i+=g,o+=1}else{if(!d)throw new Error("Unrecognized type of input");{r&&""===e.webkitRelativePath&&Object.defineProperty(e,"webkitRelativePath",{configurable:!0,enumerable:!0,get:()=>e.name});const s=(e.webkitRelativePath||e.name).split("/"),a=[c];for(const[r,c]of s.entries()){r>=1&&(l=!0);const h=a.at(-1);if(!h)throw new Error("This is a bug");const{index:f,result:p}=y(h[1],c,n);if(r<s.length-1){let e=p;if(we(e))throw new Error("A same name file already exists");e||(e=[c,[]],t?h[1].splice(f,0,e):h[1].push(e)),a.push(e)}else{let n=p;if(ye(n))throw new Error("A same name directory already exists");if(n)return;const r=e.size,s={"":{length:r}};n=[c,s],t?h[1].splice(f,0,n):h[1].push(n),u.set(s,e),i+=r,o+=1}}}}}}function fe(e,t=!1){return t&&pe(e),new Map(e)}function pe(e){for(const t of e)if(ye(t)){const e=t[1];pe(e),t[1]=new Map(e)}}function de(e){return!!e&&""in e}function ge(e){return e instanceof Map}function we(e){return!!e&&""in e[1]}function ye(e){return!!e&&!(""in e[1])}function me(e,t){return e[0]<t?-1:e[0]>t?1:0}var be;!function(e){e.V1="v1",e.V2="v2",e.HYBRID="hybrid"}(be||(be={}));const ve=16384;var Le;!function(e){e[e["16KB"]=16384]="16KB",e[e["32KB"]=32768]="32KB",e[e["64KB"]=65536]="64KB",e[e["128KB"]=131072]="128KB",e[e["256KB"]=262144]="256KB",e[e["512KB"]=524288]="512KB",e[e["1MB"]=1048576]="1MB",e[e["2MB"]=2097152]="2MB",e[e["4MB"]=4194304]="4MB",e[e["8MB"]=8388608]="8MB",e[e["16MB"]=16777216]="16MB",e[e["32MB"]=33554432]="32MB"}(Le||(Le={}));const ke={type:be.V1,addCreatedBy:!0,addCreationDate:!0,addPaddingFiles:!1,blockLength:ve,pieceLength:NaN,sortFiles:!0,isPrivate:!1},Ae={type:be.V2,addCreatedBy:!0,addCreationDate:!0,blockLength:ve,pieceLength:NaN,metaVersion:2,isPrivate:!1},Ee={type:be.HYBRID,addCreatedBy:!0,addCreationDate:!0,blockLength:ve,pieceLength:NaN,metaVersion:2,isPrivate:!1};function Re(e,t){let n=0;for(const r of e)n+=Math.ceil(r.size/t);return n}async function Ue(e,t={type:be.V1},n){switch(t.type){case be.V1:return await async function(e,t,n){const r={...ke,...t},{fileTree:i,traverseTree:o,totalFileCount:s,totalFileSize:a}=await le(e,{sort:r.sortFiles});if(0===s)return;const u=[];for(const[,e]of o(i))u.push(e);isNaN(r.pieceLength)&&(r.pieceLength=Ce(a,r.blockLength)),0!=(r.pieceLength&r.pieceLength-1)&&console.warn(`piece length ${r.pieceLength} is not a power of 2`),r.announceList=Fe(r.announceList),void 0===r.announce&&void 0!==r.announceList&&(r.announce=r.announceList[0]?.[0]);const[c,h]=Pe(0,n),{commonDir:l,name:f}=he(r.name,i);let p;if(r.name=f,r.addPaddingFiles){const e=Re(u,r.pieceLength);await h(e);const t=[],n=s-1;for(let e=n;e>=0;--e){const i=u[e];if(t.unshift(Promise.resolve(Te(i.stream(),{pieceLength:r.pieceLength,padding:e!==n,updateProgress:c}))),e===n)continue;const o=i.size%r.pieceLength;if(0===o)continue;const s=Be(r.pieceLength-o,l);u.splice(e+1,0,s)}p=Y(t).stream}else{const e=Math.ceil(a/r.pieceLength);await h(e);const{stream:t}=Y(u.map((e=>Promise.resolve(e.stream()))));p=Te(t,{pieceLength:r.pieceLength,padding:!1,updateProgress:c})}return{...void 0===r.announce?{}:{announce:r.announce},...void 0===r.announceList?{}:{"announce-list":r.announceList},...void 0===r.comment?{}:{comment:r.comment},...r.addCreatedBy?{"created by":"torrefy v2.0.3"}:{},...r.addCreationDate?{"creation date":Date.now()/1e3>>0}:{},info:{...s>1?{files:u.map((e=>{const t=(e.webkitRelativePath||e.name).split("/");return void 0!==l&&t.shift(),{...e.padding?{attr:"p"}:{},length:e.size,path:t}}))}:{length:a},name:r.name,"piece length":r.pieceLength,pieces:await new Response(p).arrayBuffer(),...r.isPrivate?{private:!0}:{}}}}(e,t,n);case be.V2:return await async function(e,t,n){const r={...Ae,...t},{fileTree:i,traverseTree:o,totalFileCount:s,totalFileSize:a}=await le(e);if(0===s)return;const u=[],c=[];for(const[e,t]of o(i))u.push(t),c.push([e,t]);if(isNaN(r.pieceLength)&&(r.pieceLength=Ce(a,r.blockLength)),r.pieceLength<r.blockLength)throw new Error(`piece length ${r.pieceLength} is smaller than block length ${r.blockLength}`);if(0!=(r.pieceLength&r.pieceLength-1))throw new Error(`piece length ${r.pieceLength} is not a power of 2`);const h=r.pieceLength/r.blockLength;r.announceList=Fe(r.announceList),void 0===r.announce&&void 0!==r.announceList&&(r.announce=r.announceList[0]?.[0]);const l=Re(u,r.pieceLength),[f]=Pe(l,n),{name:p}=he(r.name,i);r.name=p;const d=new Map;return await Promise.all(c.map((async([e,t])=>{await Se(t.stream(),d,e,{blockLength:r.blockLength,pieceLength:r.pieceLength,blocksPerPiece:h,updateProgress:f})}))),{...void 0===r.announce?{}:{announce:r.announce},...void 0===r.announceList?{}:{"announce-list":r.announceList},...void 0===r.comment?{}:{comment:r.comment},...r.addCreatedBy?{"created by":"torrefy v2.0.3"}:{},...r.addCreationDate?{"creation date":Date.now()/1e3>>0}:{},info:{"file tree":i,"meta version":r.metaVersion,name:r.name,"piece length":r.pieceLength,...r.isPrivate?{private:!0}:{}},"piece layers":d}}(e,t,n);case be.HYBRID:return await async function(e,t,n){const r={...Ee,...t},{fileTree:i,traverseTree:o,totalFileCount:s,totalFileSize:a}=await le(e);if(0===s)return;const u=[],c=[];for(const[e,t]of o(i))u.push(t),c.push([e,t]);if(isNaN(r.pieceLength)&&(r.pieceLength=Ce(a,r.blockLength)),r.pieceLength<r.blockLength)throw new Error(`piece length ${r.pieceLength} is smaller than block length ${r.blockLength}`);if(0!=(r.pieceLength&r.pieceLength-1))throw new Error(`piece length ${r.pieceLength} is not a power of 2`);const h=r.pieceLength/r.blockLength;r.announceList=Fe(r.announceList),void 0===r.announce&&void 0!==r.announceList&&(r.announce=r.announceList[0]?.[0]);const[l]=Pe(2*Re(u,r.pieceLength),n),{commonDir:f,name:p}=he(r.name,i);r.name=p;const d=new Map,g=[],w=s-1;let y=-1;for(const[e,t]of c){++y;const[n,i]=t.stream().tee();if(g.unshift(Promise.resolve(Te(n,{pieceLength:r.pieceLength,padding:y!==w,updateProgress:l}))),await Se(i,d,e,{blockLength:r.blockLength,pieceLength:r.pieceLength,blocksPerPiece:h,updateProgress:l}),y===w)break;const o=t.size%r.pieceLength;if(0===o)continue;const s=Be(r.pieceLength-o,f);u.splice(y+1,0,s)}const m=Y(g).stream;return{...void 0===r.announce?{}:{announce:r.announce},...void 0===r.announceList?{}:{"announce-list":r.announceList},...void 0===r.comment?{}:{comment:r.comment},...r.addCreatedBy?{"created by":"torrefy v2.0.3"}:{},...r.addCreationDate?{"creation date":Date.now()/1e3>>0}:{},info:{"file tree":i,...s>1?{files:u.map((e=>{const t=(e.webkitRelativePath||e.name).split("/");return void 0!==f&&t.shift(),{...e.padding?{attr:"p"}:{},length:e.size,path:t}}))}:{length:a},"meta version":r.metaVersion,name:r.name,"piece length":r.pieceLength,pieces:await new Response(m).arrayBuffer(),...r.isPrivate?{private:!0}:{}},"piece layers":d}}(e,t,n)}}async function Se(e,t,n,r){const{piecesRootReadableStream:i,pieceLayerReadableStream:o}=function(e,t){const n=e.pipeThrough(new $(t.blockLength)).pipeThrough(new q(t.blocksPerPiece)).pipeThrough(new K(t.updateProgress)),[r,i]=n.tee();return{piecesRootReadableStream:i.pipeThrough(new X(t.blocksPerPiece)).pipeThrough(new K),pieceLayerReadableStream:r}}(e,r),s=new Response(i).arrayBuffer();if(n[""].length>r.pieceLength){const e=new Response(o).arrayBuffer();t.set(await s,await e)}n[""].length>0&&(n[""]["pieces root"]=await s)}function Te(e,t){return e.pipeThrough(new $(t.pieceLength,{padding:t.padding})).pipeThrough(new W(t.updateProgress))}function Be(e,t){const n=new File([new ArrayBuffer(e)],`${e}`,{type:"application/octet-stream"}),r=`.pad/${e}`,i=void 0===t?r:`${t}/${r}`;return Object.defineProperties(n,{webkitRelativePath:{configurable:!0,enumerable:!0,get:()=>i},padding:{configurable:!0,enumerable:!1,get:()=>!0}}),n}function Pe(e,t){const n={current:0,total:e};return[async()=>{t&&await t(++n.current,n.total)},async e=>{n.total="number"==typeof e?e:await e(n.total,n.current)}]}function Fe(e){if(void 0===e)return;const t=[];for(const n of e)0!==n.length&&t.push(n);return 0!==t.length?t:void 0}function Ce(e,t){return Math.max(t,v(e>>>10))}})(),r})()));
{
"name": "torrefy",
"version": "2.0.2",
"version": "2.0.3",
"type": "module",
"files": [
"./dist/*.ts",
"./dist/*.js"
"./dist/**/*.ts",
"./dist/**/*.js"
],

@@ -16,4 +16,5 @@ "exports": {

"scripts": {
"clean": "rm -rf dist/*.js dist/*.d.ts",
"build": "npm run clean; webpack",
"clean": "rm -fr ./dist/*.*s",
"lint": "eslint ./src",
"build": "npm run lint && npm run clean && webpack",
"serve": "http-server -c-1 dist"

@@ -23,2 +24,6 @@ },

"@types/uuid": "^8.3.4",
"@types/wicg-file-system-access": "^2020.9.5",
"@typescript-eslint/eslint-plugin": "^5.43.0",
"@typescript-eslint/parser": "^5.43.0",
"eslint": "^8.28.0",
"http-server": "^14.1.1",

@@ -28,12 +33,14 @@ "mocha": "^10.1.0",

"tslib": "^2.4.1",
"typescript": "^4.8.4",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
"typescript": "^4.9.3",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.0"
},
"dependencies": {
"array-keyed-map": "^2.1.3",
"jssha": "github:Sec-ant/jsSHA#dd69d437ee912b95007a330f9afec7635f83271e",
"uuid": "^9.0.0",
"workbox-streams": "^6.5.4"
},
"peerDependencies": {
"@sec-ant/trie-map": "^1.1.5"
}
}

@@ -1,9 +0,13 @@

## This package is still under heavy development. APIs are prone to change. Use with caution!!
<div align="center">
<img width="200" src="https://user-images.githubusercontent.com/10386119/200158861-0398b9ce-35f6-4516-a79e-95ed1772b10b.svg">
<img width="200" src="https://user-images.githubusercontent.com/10386119/202842623-06e8ca3f-5761-41ed-9a8a-3a617b4e33a5.svg">
<h1>torrefy</h1>
<p>
An <a href="https://developer.mozilla.org/docs/Web/JavaScript/Guide/Modules">ESM</a> package that uses <a href="https://developer.mozilla.org/docs/Web/API/Streams_API">Web Streams API</a> to create v1, v2 or hybrid torrents in your web browser
<img src="https://img.shields.io/github/languages/top/Sec-ant/torrefy" alt="GitHub top language"> <a href="https://www.npmjs.com/package/torrefy"><img src="https://img.shields.io/npm/v/torrefy" alt="npm version"></a> <a href="https://www.npmjs.com/package/torrefy"><img src="https://img.shields.io/npm/dm/torrefy" alt="npm downloads"></a> <a href="https://www.jsdelivr.com/package/npm/torrefy"><img src="https://data.jsdelivr.com/v1/package/npm/torrefy/badge?style=rounded" alt=""></a> <img src="https://img.shields.io/github/search/Sec-ant/torrefy/goto" alt="GitHub search hit counter"> <a href="https://openbase.com/js/torrefy?utm_source=embedded&amp;utm_medium=badge&amp;utm_campaign=rate-badge"><img src="https://badges.openbase.com/js/rating/torrefy.svg?token=SBYugeYmOxDXIoCFLx5bHr1urYSXTjmWD51wO5PzyH0=" alt="Rate this package"></a>
</p>
<p>
An <a href="https://developer.mozilla.org/docs/Web/JavaScript/Guide/Modules">ESM</a> package that uses <a href="https://developer.mozilla.org/docs/Web/API/Streams_API">Web Streams API</a> to create v1, v2 or hybrid torrents in your web browser.
</p>
<p>
πŸ—This package is under active development.πŸ—
</p>
</div>

@@ -17,6 +21,4 @@

## Usage
## Basic usage
### Basic usage
```ts

@@ -41,3 +43,3 @@ import { create, encode, decode } from "torrefy";

// consume the first readable stream as an array buffer
const torrentBinary = await new Response(torrentStream).arrayBuffer();
const torrentBinary = await new Response(torrentStream1).arrayBuffer();

@@ -48,85 +50,8 @@ // decode the second readable stream into meta info

### Advance usage
## Features
```ts
import {
create,
encode,
decode,
CommonPieceLength,
TorrentType,
TorrentOptions,
OnProgress,
ArrayKeyedMap,
useArrayBufferPromiseHook,
useTextPromiseHook,
} from "torrefy";
### Supports Different Web File APIs
// create a test file
const testFile = new File(
["Hello world. This is the test file content."],
"testfile.txt"
);
This package can handle input files or directories acquired from [File API](https://developer.mozilla.org/docs/Web/API/File), [File and Directory Entries API](https://developer.mozilla.org/docs/Web/API/File_and_Directory_Entries_API) or [File System Access API](https://developer.mozilla.org/docs/Web/API/File_System_Access_API).
// v1 torrent options
const options: TorrentOptions<TorrentType.V1> = {
type: TorrentType.V1,
announceList: [
["udp://tracker.opentrackr.org:1337/announce"],
["udp://9.rarbg.com:2810/announce"],
],
pieceLength: CommonPieceLength["16KB"],
};
// handle progress
const handleProgress: OnProgress = (current, total) => {
console.log(((current / total) * 100).toFixed(2) + "%");
};
// calculate (hash) the meta info of the test file
const metaInfo = await create([testFile], options, handleProgress);
// use hooks when bencoding
const hooks = new ArrayKeyedMap();
// declare hook result as an array buffer promise
const [infoPromise, updateInfo] = useArrayBufferPromiseHook();
// register the above hook under "info" path
hooks.set(["info"], updateInfo);
// declare hook result as a text promise
const [piecesPromise, updatePieces] = useTextPromiseHook();
// register the above hook under "info.pieces" path
hooks.set(["info", "pieces"], updatePieces);
// bencode meta info into a readable stream with registered hooks
const torrentStream = encode(metaInfo, hooks);
// tee the readable stream into two readable streams
const [torrentStream1, torrentStream2] = torrentStream.tee();
// consume the first readable stream as an array buffer
const torrentBinary = await new Response(torrentStream1).arrayBuffer();
// get bencoded "info" as an array buffer
const info = await infoPromise;
// get bencoded "info.pieces" as a piece of text
const pieces = await piecesPromise;
// decode the second readable stream into meta info
const decodedMetaInfo = await decode(torrentStream2);
```
## Todos
- [x] BDecode implementation
- [ ] Magnet URI scheme (should be trivial)
- [ ] Convert all `makeXXXTransformStream` functional closure states to [`transformer`](https://developer.mozilla.org/en-US/docs/Web/API/TransformStream/TransformStream#:~:text=Parameters-,transformer,-Optional) class states (should be trivial)
- [ ] `ArrayKeyedMap` with `ArrayBuffer` keys (use proxy or drop suppport?)
- [ ] Convert typescript `Enum`s to `Union`s (need investigation)
- [ ] Other type related issues (need investigation)
- [ ] Bundleless entry (need investigation)
- [ ] Support other common BEPs (need investigation)
- [ ] Add tests
- [ ] Add demo page
### TBD
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc