axiodb
Version:
The Pure JavaScript Alternative to SQLite. Embedded NoSQL database for Node.js with MongoDB-style queries, zero native dependencies, built-in InMemoryCache, and web GUI. Perfect for desktop apps, CLI tools, and embedded systems. No compilation, no platfor
117 lines • 4.8 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.tarGzFolder = tarGzFolder;
exports.unzipFile = unzipFile;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const zlib_1 = __importDefault(require("zlib"));
const tar = __importStar(require("tar"));
/**
* Compresses a folder into a tar.gz archive.
*
* @param sourceFolder - The path to the folder to be compressed
* @param outPath - The destination path for the compressed archive
* @returns A Promise that resolves when compression is complete
*
* @example
* // Compress a folder to a tar.gz file
* await tarGzFolder('/path/to/source', '/path/to/archive.tar.gz');
*/
function tarGzFolder(sourceFolder, outPath) {
return __awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
const gzip = zlib_1.default.createGzip();
const dest = fs_1.default.createWriteStream(outPath);
tar
.c({
gzip: false, // let zlib handle gzip
cwd: path_1.default.dirname(sourceFolder),
}, [path_1.default.basename(sourceFolder)])
.pipe(gzip)
.pipe(dest)
.on("finish", () => {
resolve(outPath);
})
.on("error", reject);
});
});
}
/**
* Unzips a .tar.gz file to a specified destination folder
*
* @param zipFilePath - The path to the compressed file to be unzipped
* @param destFolder - The destination folder where the contents will be extracted
* @returns A promise that resolves with the destination folder path when unzipping is complete
* @throws Will reject the promise with an error if unzipping fails
*
* @example
* ```typescript
* try {
* const extractedPath = await unzipFile('/path/to/archive.tar.gz', '/path/to/destination');
* console.log(`Files extracted to ${extractedPath}`);
* } catch (error) {
* console.error('Failed to unzip file:', error);
* }
* ```
*/
function unzipFile(zipFilePath, destFolder) {
return __awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
const unzip = zlib_1.default.createUnzip();
const source = fs_1.default.createReadStream(zipFilePath);
source
.pipe(unzip)
.pipe(tar.x({ C: destFolder }))
.on("finish", () => {
resolve(destFolder);
})
.on("error", reject);
});
});
}
//# sourceMappingURL=ZipUnzip.utils.js.map