icebox/dist/file/index.js

62 lines
1.5 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.File = void 0;
const promises_1 = require("fs/promises");
const path_1 = require("path");
const size_1 = require("../size");
const hash_1 = require("../hash");
class File {
static async info(filePath) {
const original = (0, path_1.resolve)(filePath);
const filename = (0, path_1.basename)(filePath);
let success = false;
let hash;
let fileSize;
let created;
let stats;
let error;
try {
hash = await hash_1.Hashes.file(filePath);
}
catch (err) {
error = err;
return {
success,
error
};
}
try {
fileSize = await (0, size_1.size)(filePath);
}
catch (err) {
error = err;
return {
success,
error
};
}
try {
stats = await (0, promises_1.stat)(filePath);
created = stats.birthtimeMs;
}
catch (err) {
error = err;
return {
success,
error
};
}
success = true;
return {
success,
filename,
original,
hash,
size: fileSize,
created
};
}
}
exports.File = File;
module.exports = { File };
//# sourceMappingURL=index.js.map