Tory is a JavaScript/TypeScript library providing an object-oriented API for interacting with the filesystem. It offers `ToryFile` and `ToryFolder` classes that represent files and directories, respectively. Key features include lazy loading of file system data, customizable recursive iteration rules, and methods for retrieving file hashes, sizes, and modification times. The current stable version is 0.4.4. Based on its release history, which shows the last significant development in early 2020 with minor dependency updates since, the project appears to have an inactive release cadence. Its primary differentiator is the `Filer` abstraction and flexible iteration strategies, including custom rules for traversing directories, which can be useful for complex file system operations.
npm install toryVerified import paths — ran on the pinned version, not inferred.
This example demonstrates creating ToryFolder and ToryFile instances, iterating over directory contents (both shallow and recursive), and fetching file metadata like hash, size, and modification time. It sets up and cleans up a temporary directory.
Review the README for the new class-based API. Migrate existing code to use `new ToryFile()` and `new ToryFolder()` instances and their methods.
Consult the README for the 0.2.0 API structure, or ideally, upgrade directly to the latest version (0.4.x) and follow its migration path.
Always use `await` when calling methods like `getHash()`, `getSize()`, or `getModifyTime()`, as they return Promises and perform I/O.
Ensure the path provided to the `ToryFile` or `ToryFolder` constructor points to an existing file or directory.
For CommonJS, use `const { ToryFile, ToryFolder } = require('tory');`. For ES Modules, use `import { ToryFile, ToryFolder } from 'tory';`.Add error handling (try/catch) around the instantiation of `ToryFile` or `ToryFolder` and ensure the variable holds a valid instance before calling its methods.