Registry / serialization / tory
library0.1jsnpmunverified

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 tory
INSTALL
IMPORT
SIG · TORY
T
tory
serializationjavascriptv0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ToryFile
import { ToryFile } from 'tory';
const ToryFile = require('tory').ToryFile;
Use named import for ES Modules. While `require` works for CJS, destructuring is recommended.
ToryFolder
import { ToryFolder } from 'tory';
const ToryFolder = require('tory'); // Incorrectly imports the entire module, not the specific class
ToryFolder is a named export. For CommonJS, destructure from the require call.
CommonJS all exports
const { ToryFile, ToryFolder } = require('tory');
This pattern allows access to both ToryFile and ToryFolder classes in CommonJS environments.

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.

import { ToryFile, ToryFolder } from 'tory'; import * as path from 'path'; import * as fs from 'fs'; const tempDir = path.join(__dirname, 'temp_tory_test'); fs.mkdirSync(tempDir, { recursive: true }); fs.writeFileSync(path.join(tempDir, 'file1.txt'), 'hello world'); fs.mkdirSync(path.join(tempDir, 'subdir')); fs.writeFileSync(path.join(tempDir, 'subdir', 'file2.txt'), 'another file'); async function runToryExample() { try { const sourceFolder = new ToryFolder(tempDir); console.log(` --- Listing contents of '${sourceFolder.path}' ---`); for (const filer of sourceFolder) { console.log(`Visited: ${filer.name} (${filer.type}) - Path: ${filer.path}`); } console.log(` --- Iterating recursively ---`); for (const filer of sourceFolder.toDefaultRecursiveIterable()) { console.log(`Visited recursively: ${filer.name} (${filer.type})`); } const file = new ToryFile(path.join(tempDir, 'file1.txt')); console.log(` --- File details for '${file.name}' ---`); console.log(`SHA256: ${await file.getHash()}`); console.log(`Size (bytes): ${await file.getSize()}`); console.log(`Modify Time: ${await file.getModifyTime()}`); } catch (error) { console.error('An error occurred:', error.message); } finally { fs.rmSync(tempDir, { recursive: true, force: true }); console.log(` Cleaned up temporary directory: ${tempDir}`); } } runToryExample();
Debug
Known issues
breakingVersion 0.4.0 introduced a full rewrite, drastically changing the API. It introduced `ToryFile` and `ToryFolder` classes as the primary interface for filesystem operations.
fix
Review the README for the new class-based API. Migrate existing code to use `new ToryFile()` and `new ToryFolder()` instances and their methods.
affects: >=0.4.0
breakingVersion 0.2.0 also involved a complete API change. Users migrating from pre-0.2.0 versions will need to update their code significantly.
fix
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.
affects: >=0.2.0 <0.4.0
gotchaTory utilizes lazy loading for all disk operations. While beneficial for performance, properties like file hashes or sizes are not available immediately upon object instantiation and must be explicitly requested, often via `async` methods.
fix
Always use `await` when calling methods like `getHash()`, `getSize()`, or `getModifyTime()`, as they return Promises and perform I/O.
affects: >=0.4.0
Errors
Common errors & fixes
Error: ENOENT: no such file or directory, stat '<path>'
Attempting to instantiate `new ToryFile()` or `new ToryFolder()` with a path that does not exist on the filesystem.
fix
Ensure the path provided to the `ToryFile` or `ToryFolder` constructor points to an existing file or directory.
TypeError: ToryFile is not a constructor
Attempting to use `ToryFile` or `ToryFolder` without properly destructuring them from the CommonJS `require()` call or using a wrong import in ES Modules.
fix
For CommonJS, use `const { ToryFile, ToryFolder } = require('tory');`. For ES Modules, use `import { ToryFile, ToryFolder } from 'tory';`.
TypeError: Cannot read properties of undefined (reading 'getHash')
This typically occurs if a `ToryFile` or `ToryFolder` instance was not successfully created (e.g., due to a non-existent path) but subsequent methods are called on the `undefined` variable.
fix
Add error handling (try/catch) around the instantiation of `ToryFile` or `ToryFolder` and ensure the variable holds a valid instance before calling its methods.
Upgrade
Version history
0.1latest on npm
Audit
Dependencies
ellipticrequiredInternal cryptographic utility, likely for hashing.
lodashrequiredInternal utility functions.
Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
tory — npm install tory · libregistry