Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 13x 13x 13x 13x 13x 13x 13x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 12x 12x 12x 12x 12x 12x 12x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 5x 5x 1x 1x 1x 1x 1x 1x 1x 5x 5x 5x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x | /*
* Copyright (c) 2025 Erik Fortune
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import { Result } from '@fgv/ts-utils';
import { FileTree } from '@fgv/ts-json-base';
import { FileApiTreeAccessors, IFileMetadata } from '../file-tree/fileApiTreeAccessors';
/**
* Default initialization parameters for a `FileTree` using {@link FileApiTreeAccessors}.
* @public
*/
export const defaultFileApiTreeInitParams: FileTree.IFileTreeInitParams<string> = {
inferContentType: FileTree.FileItem.defaultAcceptContentType
};
/**
* Helper function to create a new FileTree instance
* from a browser FileList (e.g., from input[type="file"]).
* @param fileList - FileList from a file input element
* @param params - Optional `IFileTreeInitParams` for the file tree.
* @returns Promise resolving to a successful Result with the new FileTree instance
* if successful, or a failed Result with an error message otherwise
* @remarks The content type of the files is always `string` and the default
* accept contentType function (`FileTree.FileItem.defaultAcceptContentType`) is
* used, so content type is derived from the mime type of the file, when
* available.
* @public
*/
export function fromFileList(
fileList: FileList,
params?: FileTree.IFileTreeInitParams<string>
): Promise<Result<FileTree.FileTree<string>>> {
params = { ...defaultFileApiTreeInitParams, ...(params ?? {}) };
return FileApiTreeAccessors.fromFileList(fileList, params);
}
/**
* Helper function to create a new FileTree instance
* from a directory upload with webkitRelativePath support.
* @param fileList - FileList from a directory upload (input with webkitdirectory)
* @param params - Optional `IFileTreeInitParams` for the file tree.
* @returns Promise resolving to a successful Result with the new FileTree instance
* if successful, or a failed Result with an error message otherwise
* @remarks The content type of the files is always `string` and the default
* accept contentType function (`FileTree.FileItem.defaultAcceptContentType`) is
* is used, so content type is derived from the mime type of the file, when
* available.
* @public
*/
export function fromDirectoryUpload(
fileList: FileList,
params?: FileTree.IFileTreeInitParams<string>
): Promise<Result<FileTree.FileTree<string>>> {
params = { ...defaultFileApiTreeInitParams, ...(params ?? {}) };
return FileApiTreeAccessors.fromDirectoryUpload(fileList, params);
}
/**
* Helper function to get the original File object from a FileList by path.
* @param fileList - The original FileList
* @param path - The path to the file
* @returns A successful Result with the File object if found,
* or a failed Result with an error message otherwise
* @public
*/
export function getOriginalFile(fileList: FileList, path: string): Result<File> {
return FileApiTreeAccessors.getOriginalFile(fileList, path);
}
/**
* Helper function to extract metadata from a `FileList`.
* @param fileList - The `FileList` to extract metadata from
* @returns Array of {@link IFileMetadata | file metadata} objects
* @public
*/
export function extractFileListMetadata(fileList: FileList): Array<IFileMetadata> {
return Array.from(fileList).map((f) => FileApiTreeAccessors.extractFileMetadata(f));
}
/**
* Helper function to extract metadata from a `File`.
* @param file - The File to extract metadata from
* @returns {@link IFileMetadata | file metadata} object
* @public
*/
export function extractFileMetadata(file: File): IFileMetadata {
return FileApiTreeAccessors.extractFileMetadata(file);
}
|