1.0.2 • Published 7 years ago
fs-zip v1.0.2
fs-zip
Fs module that treats Zips as folders
Description
'fs-zip' is a Node.js module that supports zip file operations while implementing a 'fs'-like API. The API only supports asynchronous calls (promise and callback based) and currently only support the most important 'fs' functions. The main purpose of this module is to provide a seamless API which works for normal file system operations as well as zip operations.
Installation
You can install 'fs-zip' using NPM.
npm install --save fs-zip
Examples
import * as fs from 'fs-zip'
// Zip operations
fs.readdir('/home/user/Documents/test.zip/subdir')
.then(res => console.log(res))
fs.readFile('/home/user/Documents/test.zip/subdir/file.txt', 'utf8', (err, text) => {
console.log(text)
})
// Filesystem operations
fs.readdir('/home/user/Documents/')
.then(res => console.log(res))
fs.readFile('/home/user/Documents/file.txt', 'utf8', (err, text) => {
console.log(text)
})
Limitations
Since 'fs-zip' current uses JsZip for zip operations, the limitations of JsZip also apply to 'fs-zip'.
API Documentation
/**
* Asynchronously creates an empty file
* @param file A path to a file or directory.
*/
function createFile(file: string): Promise<void>
/**
* Asynchronously creates an empty file
* @param file A path to a file or directory.
*/
function createFile(file: string, callback: (err: Error) => void): void
/**
* Asynchronously tests whether or not the given path exists by checking with the file system.
* @param pathStr A path to a file or directory.
*/
function exists(pathStr: string): Promise<boolean>
/**
* Asynchronously tests whether or not the given path exists by checking with the file system.
* @param pathStr A path to a file or directory.
*/
function exists(pathStr: string, callback: (err: Error, exists: boolean) => void): void
/**
* Asynchronously tests whether or not the given path exists by checking with the file system.
* @param pathStr A path to a file or directory.
*/
function pathExists(pathStr: string): Promise<boolean>
/**
* Asynchronously tests whether or not the given path exists by checking with the file system.
* @param pathStr A path to a file or directory.
*/
function pathExists(pathStr: string, callback: (err: Error, exists: boolean) => void): void
/**
* Asynchronous readdir - read a directory. Returns list of directory contents.
* @param dirPath A path to a directory
*/
function readdir(dirPath: string): Promise<string[]>
/**
* Asynchronous readdir - read a directory. Returns list of directory contents.
* @param dirPath A path to a directory
*/
function readdir(dirPath: string, callback: (err: Error, res: string[]) => void): void
/**
* Asynchronously reads the entire contents of a file.
* @param file A path to a file.
* @param encoding String specifying the encoding of the file
*/
function readFile(file: string, encoding: string): Promise<string>
/**
* Asynchronously reads the entire contents of a file.
* @param file A path to a file.
*/
function readFile(file: string): Promise<Buffer>
/**
* Asynchronously reads the entire contents of a file.
* @param file A path to a file.
* @param encoding String specifying the encoding of the file
*/
function readFile(file: string, encoding: string, callback: (err: Error, res: string) => void): void
/**
* Asynchronously reads the entire contents of a file.
* @param file A path to a file.
*/
function readFile(file: string, callback: (err: Error, res: Buffer) => void): void
/**
* Asynchronously reads and parses a Json file.
* @param file A path to a file.
*/
function readJson<T>(file: string): Promise<T>
/**
* Asynchronously reads and parses a Json file.
* @param file A path to a file.
*/
function readJson<T>(file: string, callback: (err: Error, res: T) => void): void
/**
* Asynchronously removes a file or directory.
* @param dirPath A path to a file or directory.
*/
function remove(pathStr: string): Promise<void>
/**
* Asynchronously removes a file or directory.
* @param dirPath A path to a file or directory.
*/
function remove(pathStr: string, callback: (err: Error) => void): void
/**
* Asynchronous stat(2) - Get file status.
* @param pathStr A path to a file.
*/
function stat(pathStr: string): Promise<Stats>
/**
* Asynchronous stat(2) - Get file status.
* @param pathStr A path to a file.
*/
function stat(pathStr: string, callback: (err: Error, res: Stats) => void): void
/**
* Asynchronously writes data to a file, replacing the file if it already exists.
* @param path A path to a file.
* @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
*/
function writeFile(file: string, data: any): Promise<void>
/**
* Asynchronously writes data to a file, replacing the file if it already exists.
* @param path A path to a file.
* @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
*/
function writeFile(file: string, data: any, callback: (err: Error) => void): void
/**
* Asynchronously writes object to a Json file, replacing the file if it already exists.
* @param path A path to a file.
* @param obj The object to write.
*/
function writeJson(file: string, obj: any): Promise<void>
/**
* Asynchronously writes object to a Json file, replacing the file if it already exists.
* @param path A path to a file.
* @param obj The object to write.
*/
function writeJson(file: string, obj: any, callback: (err: Error) => void): void