1
0
Fork 0
salty-dog/src/source.ts

24 lines
583 B
TypeScript
Raw Normal View History

import { promisify } from 'util';
2019-06-16 01:21:11 +00:00
import { readFile, writeFile } from 'fs';
export const readFileSync = promisify(readFile);
export const writeFileSync = promisify(writeFile);
export async function loadSource(path: string): Promise<string> {
if (path === '-') {
return readFileSync(0, 'utf-8');
} else {
return readFileSync(path, 'utf-8');
}
}
2019-06-16 01:21:11 +00:00
export async function writeSource(path: string, data: string): Promise<void> {
if (path === '-') {
process.stdout.write(data);
} else {
return writeFileSync(path, data, {
encoding: 'utf-8',
});
}
}