seczure.ts
v1.0.5
Published
Node.js native integration TypeScript library for sf-api
Maintainers
Readme
Seczure.ts
A Node.js native integration TypeScript library for sf-api secure filesystem operations.
Overview
Seczure.ts provides a TypeScript interface to the sf-api C library, enabling secure filesystem operations through a native Node.js addon. The library includes the FsShellLib class which bridges the extern C functions from sf-api.h.
Features
- Native Performance: Direct integration with sf-api C library
- TypeScript Support: Full type definitions and IntelliSense support
- Comprehensive API: Covers disk operations, file operations, and filesystem management
- Error Handling: Proper error codes and exception handling
- Memory Management: Safe buffer operations and memory cleanup
Installation
pnpm install
pnpm run buildPrerequisites
- Node.js >= 16.0.0
- Python (for node-gyp)
- C++ compiler (GCC, Clang, or MSVC)
- sf-api library installed on your system
Usage
Basic Example
import { FsShellLib } from 'seczure.ts';
const fsShell = new FsShellLib();
// Get library version
const version = fsShell.getVersion();
console.log('SF Library Version:', version);
// Get available drives
const driveInfo = fsShell.diskGetDrives(1024);
if (FsShellLib.isSuccess(driveInfo.result)) {
const drives = FsShellLib.parseDriveList(driveInfo.drives);
console.log('Available drives:', drives);
}
// Open a disk
const openResult = fsShell.diskOpen('D:', 'password123');
if (FsShellLib.isSuccess(openResult)) {
console.log('Disk opened successfully');
// Perform file operations...
// Close the disk
fsShell.diskClose();
}File Operations
// Create a new file
const fd = fsShell.create('/path/to/file.txt');
if (fd >= 0) {
// Write data
const data = Buffer.from('Hello, World!', 'utf8');
const bytesWritten = fsShell.write(fd, data);
// Read data
const readResult = fsShell.read(fd, 1024);
console.log('Read data:', readResult.buffer.toString('utf8'));
// Close file
fsShell.close(fd);
}Directory Operations
// Get file list
const fileListResult = fsShell.getFileList('/path/to/directory');
if (FsShellLib.isSuccess(fileListResult.result)) {
const files = FsShellLib.parseFileList(fileListResult.fileList);
console.log('Files:', files);
}API Reference
FsShellLib Class
Version and Test Methods
getVersion(): string- Get SF library versiontest(): string- Test SF library functionalitygetLastError(): number- Get last error code
Disk Operations
diskSetDriverMode(mode: number): number- Set disk driver modediskGetCount(): number- Get number of available disksdiskGetDrives(bufferLength?: number): DriveInfo- Get available drivesdiskOpen(drive: string, password: string): number- Open disk with passworddiskClose(): number- Close currently opened disk
File Operations
create(filename: string): number- Create new fileopen(filename: string): number- Open file for read/writeclose(fd: number): number- Close fileread(fd: number, length: number): ReadResult- Read from filewrite(fd: number, buffer: Buffer): number- Write to file
Directory Operations
getFileList(path: string): FileListResult- Get directory file list
Utility Methods
static isSuccess(result: number): boolean- Check if result indicates successstatic parseDriveList(driveString: string): string[]- Parse drive list stringstatic parseFileList(fileListString: string): string[]- Parse file list string
Building
Build Native Addon
pnpm run build:nativeBuild TypeScript
pnpm run build:tsBuild All
pnpm run buildClean Build
pnpm run cleanTesting
pnpm testError Handling
All SF functions return integer error codes where 0 indicates success. Use FsShellLib.isSuccess(result) to check for successful operations.
const result = fsShell.diskOpen('D:', 'password');
if (!FsShellLib.isSuccess(result)) {
const errorCode = fsShell.getLastError();
console.error('Failed to open disk, error code:', errorCode);
}License
MIT
Contributing
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
