@hilesystem/local v1.1.0

HileSystem Local
Filesystem abstraction layer and common function wrappers.
Usage
Import
import {
HileSystemLocal,
absolutePathFrom, pathFrom,
createDirectory, createFile,
readFileToBase64, readFileToBuffer, readFileToString,
dirIsEmpty, dirIsExecutable, dirIsReadable, dirIsVisible, dirIsWritable,
fileIsExecutable, fileIsReadable, fileIsVisible, fileIsWritable,
getStatus, isDirExists, isFileExists, isPathExists,
fileExtension, fileName, fileNameExt, filePath,
listContents, listDirectories, listFiles,
move,
remove, removeNonBlocking, removeSilent,
fileTruncate, writeFile, writeFileTail, writeJSON,
hash, hashCrc32, hashMd5, hashSha1, hashSha256, hashSha512, size,
} from "@hilesystem/local";Import all as named import
import * as hileSystem from "@hilesystem/local";
const isDirectoryCreated = await hileSystem.createDirectory("./test/");Working with instance
If you prefer object-oriented style.
import { HileSystemLocal } from "@hilesystem/local";
const hileSystem = new HileSystemLocal();
const isDirectoryCreated = await hileSystem.createDirectory("./test/");API
Path
const paths = ["path", "to", "file.txt"];
const str = absolutePathFrom(paths) // "/user/me/path/to/file.txt"const str = fileExtension("path/to/file.txt"); // "txt"const str = fileName("path/to/file.txt"); // "file"const str = fileNameExt("path/to/file.txt"); // "file.txt"const str = filePath("path/to/file.txt"); // "path/to"const str = pathFrom(["path", "to", "file.txt"]) // "path/to/file.txt"Create
const trueOrError = await createDirectory("path/to/dir", "0777", true);const trueOrError = await createFile("path/to/dir", "0777");Read
const stringOrError = await readFileToBase64("path/to/img.png");const bufferOrError = await readFileToBuffer("path/to/file.txt");const stringOrError = await readFileToString("path/to/file.txt");Move
const trueOrError = await move("path/to/file.ext", "path/to-another/file.ext");Write
const trueOrError = await fileTruncate("path/to/file.ext");const filePath = "./file.txt";
const data = "Text";
const options = { encoding: "utf8" };
const trueOrError = await writeFile(filePath, data, options);const filePath = "./file.txt";
const data = "Text to add to the end of the file.";
const options = { encoding: "utf8" };
const trueOrError = await writeFileTail(filePath, data, options);const filePath = "./file.json";
const data = { key: "value" };
const options = { encoding: "utf8" };
const config = {
sort: true,
space: "\t"
};
const trueOrError = await writeJSON(filePath, data, options, config);Delete
const voidOrError = await remove("path/to/file.txt");removeNonBlocking("path/to/file.txt");removeSilent("path/to/file.txt");Information
const [status, error] = await getStatus("path/to/file.ext");const trueOrFalse = await isDirExists("path/to/");const trueOrFalse = await isFileExists("path/to/file.ext");const trueOrFalse = await isPathExists("path/to/file_or_directory");Check
const booleanOrError = await dirIsEmpty("path/to/dir", true);const trueOrError = await dirIsExecutable("path/to/dir");const trueOrError = await dirIsReadable("path/to/dir");const trueOrError = await dirIsVisible("path/to/dir");const trueOrError = await dirIsWritable("path/to/dir");const trueOrError = await fileIsExecutable("path/to/file.ext");const trueOrError = await fileIsReadable("path/to/file.ext");const trueOrError = await fileIsVisible("path/to/file.ext");const trueOrError = await fileIsWritable("path/to/file.ext");List
const arrayOfStringsOrError = await listContents("path/to/dir");const arrayOfStringsOrError = await listDirectories("path/to/dir");const arrayOfStringsOrError = await listFiles("path/to/dir");Calculate
const hash = await hash("path/to/file", "md5");const hash = await hashCrc32("path/to/file");const hash = await hashMd5("path/to/file");const hash = await hashSha1("path/to/file");const hash = await hashSha256("path/to/file");const hash = await hashSha512("path/to/file");const sizeInBytes = await size("path/to/file");
const sizeAsString = await size("path/to/file", true);See also
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago