Don't read the file twice
This commit is contained in:
parent
19252467cb
commit
52fb900603
|
@ -245,9 +245,9 @@ async function run_non_interactively(files, argv) {
|
||||||
|
|
||||||
exports.handler = async argv => {
|
exports.handler = async argv => {
|
||||||
const files = [...(argv.files || []), argv.file].map(file_path => {
|
const files = [...(argv.files || []), argv.file].map(file_path => {
|
||||||
|
const buffer = fs.readFileSync(file_path);
|
||||||
const encoding =
|
const encoding =
|
||||||
(fs
|
(buffer
|
||||||
.readFileSync(file_path)
|
|
||||||
.toString()
|
.toString()
|
||||||
.split('')
|
.split('')
|
||||||
.some(x => x.charCodeAt(0) >= 128) &&
|
.some(x => x.charCodeAt(0) >= 128) &&
|
||||||
|
@ -255,7 +255,7 @@ exports.handler = async argv => {
|
||||||
'utf8';
|
'utf8';
|
||||||
return {
|
return {
|
||||||
name: path.basename(file_path),
|
name: path.basename(file_path),
|
||||||
content: fs.readFileSync(file_path).toString(encoding),
|
content: buffer.toString(encoding),
|
||||||
encoding,
|
encoding,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue