UNPKG

als-store

Version:

Library for streamlined file management and advanced data caching, featuring intelligent file searching, dynamic cache control, and flexible file operations

25 lines (15 loc) 1.47 kB
### File Class Constructor #### Overview: The `File` class constructor creates an instance of `File`, designed to manage a file within a specified directory. It supports validation, caching, and data management of the file. #### Constructor Parameters: 1. **`path` (String, required)**: The path to the directory where the file is located. This parameter specifies the file's location in the file system but does not include the file name itself. 2. **`name` (String, required)**: The name of the file. It is used for identifying and managing the file within its directory. 3. **`schema` (Schema, optional)**: An instance of the `Schema` class used for generating file parameters from its name and vice versa. The schema allows for the transformation of the file name into a structured set of data (e.g., `{name: 'Alex Smith', age: 25}` from the file name `Alex Smith.25`) and ensures data validation. #### Functionality Description: - When creating a `File` instance, the constructor initializes key properties of the file, such as path, name, and size. - If a schema is provided for the file, it is used to generate parameters from the file name and to convert parameters back into a name. - The constructor also manages the addition of the file to the cache, updating the size of cached data and ensuring efficient memory usage. #### Usage Example: ```js const file = new File('/path/to/directory', 'example.txt', userSchema); ```