@ducktors/storagebus-local
Advanced tools
Comparing version 0.11.0 to 0.12.0
@@ -20,4 +20,3 @@ /// <reference types="node" /> | ||
move(filePath: string, destFilePath: string): Promise<string>; | ||
static getTmpSubFolder(subFolder?: string): Promise<string>; | ||
} | ||
export {}; |
@@ -5,3 +5,2 @@ "use strict"; | ||
const tslib_1 = require("tslib"); | ||
const node_crypto_1 = require("node:crypto"); | ||
const node_fs_1 = require("node:fs"); | ||
@@ -22,6 +21,13 @@ const promises_1 = tslib_1.__importDefault(require("node:fs/promises")); | ||
}); | ||
this.bucket = opts.bucket ?? opts.rootFolder; | ||
let rootFolder = opts.bucket ?? opts.rootFolder; | ||
if (!(0, node_path_1.isAbsolute)(rootFolder)) { | ||
const tmpDir = (0, node_os_1.tmpdir)(); | ||
rootFolder = (0, node_path_1.join)(tmpDir, rootFolder); | ||
} | ||
(0, node_fs_1.mkdirSync)(rootFolder, { recursive: true }); | ||
this.bucket = rootFolder; | ||
} | ||
async write(filePath, fileReadable) { | ||
const path = (0, node_path_1.join)(this.bucket, filePath); | ||
await promises_1.default.mkdir((0, node_path_1.dirname)(path), { recursive: true }); | ||
await (0, promises_2.pipeline)(fileReadable, (0, node_fs_1.createWriteStream)(path)); | ||
@@ -40,3 +46,6 @@ return filePath; | ||
} | ||
return false; | ||
if (err.code === 'ENOENT') { | ||
return false; | ||
} | ||
throw err; | ||
} | ||
@@ -55,2 +64,3 @@ } | ||
const destPath = (0, node_path_1.join)(this.bucket, destFilePath); | ||
await promises_1.default.mkdir((0, node_path_1.dirname)(destPath), { recursive: true }); | ||
await promises_1.default.copyFile(path, destPath); | ||
@@ -62,2 +72,3 @@ return destFilePath; | ||
const destPath = (0, node_path_1.join)(this.bucket, destFilePath); | ||
await promises_1.default.mkdir((0, node_path_1.dirname)(destPath), { recursive: true }); | ||
try { | ||
@@ -77,14 +88,4 @@ await promises_1.default.rename(path, destPath); | ||
} | ||
static async getTmpSubFolder(subFolder) { | ||
if (!subFolder) { | ||
subFolder = (0, node_crypto_1.randomUUID)(); | ||
} | ||
const path = (0, node_path_1.join)((0, node_os_1.tmpdir)(), subFolder); | ||
await promises_1.default.mkdir(path, { | ||
recursive: true, | ||
}); | ||
return path; | ||
} | ||
} | ||
exports.Storage = Storage; | ||
//# sourceMappingURL=local.js.map |
{ | ||
"name": "@ducktors/storagebus-local", | ||
"version": "0.11.0", | ||
"version": "0.12.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12706