1
0
mirror of https://github.com/misskey-dev/misskey synced 2024-12-23 19:19:05 +09:00
misskey/src/misc/download-text-file.ts

26 lines
605 B
TypeScript
Raw Normal View History

import * as fs from 'fs';
import * as util from 'util';
import Logger from '../services/logger';
import { createTemp } from './create-temp';
2020-04-11 19:49:25 +09:00
import { downloadUrl } from './download-url';
const logger = new Logger('download-text-file');
export async function downloadTextFile(url: string): Promise<string> {
// Create temp file
const [path, cleanup] = await createTemp();
logger.info(`Temp file is ${path}`);
try {
// write content at URL to temp file
await downloadUrl(url, path);
const text = await util.promisify(fs.readFile)(path, 'utf8');
return text;
} finally {
cleanup();
}
}