@stryke/fs
Version:
A package containing various file system utilities that expand the functionality of NodeJs's built-in `fs` module.
29 lines (27 loc) • 1.82 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
const require_is_file = require('./is-file.cjs');
const require_list_files = require('./list-files.cjs');
const require_read_file = require('./read-file.cjs');
const require_write_file = require('./write-file.cjs');
let _stryke_path = require("@stryke/path");
let nanotar = require("nanotar");
let _stryke_convert_uint8_array_to_string = require("@stryke/convert/uint8-array-to-string");
let _stryke_path_join_paths = require("@stryke/path/join-paths");
//#region src/compress.ts
/**
* Compress a directory or file into a tar.gz archive.
*
* @param directory - The source directory or file/glob to compress.
* @param options - Options for the compression.
*/
async function compressDirectory(directory, options) {
const files = await require_list_files.listFiles(require_is_file.isDirectory(directory) ? (0, _stryke_path_join_paths.joinPaths)(directory, "**/*") : directory, options);
const data = await (0, nanotar.createTarGzip)(await Promise.all(files.map(async (file) => ({
name: file,
data: await require_read_file.readFileIfExisting(file)
}))), { attrs: { group: "storm-software" } });
return require_write_file.writeFile(options?.destination ? require_is_file.isDirectory(options.destination) ? (0, _stryke_path_join_paths.joinPaths)(options.destination, `${(/* @__PURE__ */ new Date()).getTime()}.tar.gz`) : options.destination : require_is_file.isDirectory(directory) ? `${(0, _stryke_path_join_paths.joinPaths)((0, _stryke_path.resolveParentPath)(directory), (0, _stryke_path.findFolderName)(directory))}.tar.gz` : directory, (0, _stryke_convert_uint8_array_to_string.uint8ArrayToString)(data));
}
//#endregion
exports.compressDirectory = compressDirectory;