import { FileDirLikes } from "./fileDirLike.js"; import { BObject } from "./codec.js"; /** * symlink file attribute */ export type SymlinkAttr = "s"; /** * executable file attribute */ export type ExecutableAttr = "x"; /** * hidden file attribute */ export type HiddenAttr = "h"; /** * padding file attribute */ export type PaddingFileAttr = "p"; /** * permutations template */ export type Permutations = T extends unknown ? T | `${T}${Permutations>}` : never; /** * file attributes */ export type FileAttrs = Permutations; /** * base file props */ export 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 type FileListV1 = FilePropsV1[]; /** * v2 file tree file node */ export interface FileTreeFileNode 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 file entry */ export type FileTreeFileEntry = [filename: string, value: FileTreeFileNode]; /** * v2 file tree dir node */ export type FileTreeDirNode = Map; /** * v2 dir entry */ export type FileTreeDirEntry = [dirname: string, value: FileTreeEntries]; /** * v2 packed dir entry */ export type PackedFileTreeDirEntry = [dirname: string, value: FileTreeDirNode]; /** * v2 file or dir entries */ export type FileTreeEntries = (FileTreeFileEntry | FileTreeDirEntry)[]; /** * v2 packed file or dir entries */ export type PackedFileTreeEntries = (FileTreeFileEntry | PackedFileTreeDirEntry)[]; export declare function resolveCommonDirAndTorrentName(name: string | undefined, fileTree: FileTreeDirNode): { name: string; commonDir: string | undefined; }; export type PopulateOptions = { sort?: false; compareFunction?: never; polyfillWebkitRelativePath?: boolean; } | { sort?: true; compareFunction?: (entry: FileTreeFileEntry | FileTreeDirEntry, name: string) => number; polyfillWebkitRelativePath?: boolean; }; export type TraverseTree = (node: FileTreeDirNode | FileTreeFileNode) => Generator<[FileTreeFileNode, File], void, unknown>; /** * Parse file-dir-likes into a file tree * @param fileDirLikes * @param opts populate options * @returns file tree and a traverse function */ export declare function populateFileTree(fileDirLikes: FileDirLikes, { sort, compareFunction, polyfillWebkitRelativePath, }?: PopulateOptions): Promise<{ fileTree: FileTreeDirNode; traverseTree: TraverseTree; totalFileSize: number; totalFileCount: number; }>; export declare function packEntriesToDirNode(entries: PackedFileTreeEntries | FileTreeEntries, shouldDeepPack?: boolean): FileTreeDirNode; export declare function isFileTreeFileNode(node: FileTreeFileNode | FileTreeDirNode | undefined): node is FileTreeFileNode; export declare function isFileTreeDirNode(node: FileTreeFileNode | FileTreeDirNode | undefined): node is FileTreeDirNode; export declare function isFileTreeFileEntry(entry: FileTreeFileEntry | FileTreeDirEntry | undefined): entry is FileTreeFileEntry; export declare function isFileTreeDirEntry(entry: FileTreeFileEntry | FileTreeDirEntry | undefined): entry is FileTreeDirEntry; export declare function compareEntryNames(entry: FileTreeFileEntry | FileTreeDirEntry, name: string): 1 | 0 | -1;