sourcecontrol
Version:
A modern TypeScript CLI application for source control
51 lines • 1.85 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.hashFiles = exports.hashStdin = void 0;
const hash_object_display_1 = require("./hash-object.display");
const utils_1 = require("../../utils");
const objects_1 = require("../../core/objects");
const utils_2 = require("../../utils");
const hashStdin = async (repository) => {
const chunks = [];
return new Promise((resolve, reject) => {
process.stdin.on('data', (chunk) => {
chunks.push(chunk);
});
process.stdin.on('end', async () => {
try {
const content = Buffer.concat(chunks);
await hashContent(new Uint8Array(content), repository, '<stdin>', false);
resolve();
}
catch (error) {
reject(error);
}
});
process.stdin.on('error', reject);
});
};
exports.hashStdin = hashStdin;
const hashFiles = async (fileList, repository, write) => {
for (const fileName of fileList) {
try {
const content = await utils_2.FileUtils.readFile(fileName);
await hashContent(new Uint8Array(content), repository, fileName, write);
}
catch (error) {
utils_1.logger.error(`cannot read '${fileName}': ${error.message}`);
process.exit(1);
}
}
};
exports.hashFiles = hashFiles;
const hashContent = async (content, repository, source, write) => {
const blob = new objects_1.BlobObject(content);
const hash = await blob.sha();
if (write && repository) {
await repository.writeObject(blob);
utils_1.logger.debug(`Stored object ${hash}`);
return;
}
(0, hash_object_display_1.printPrettyResult)(hash, source, content.length, write);
};
//# sourceMappingURL=hash-object.handler.js.map
;