Use promises API (#11351)

This commit is contained in:
woxtu 2023-07-27 09:04:19 +09:00 committed by GitHub
parent 5083458071
commit cb0fa9a8ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 17 deletions

View file

@ -1,6 +1,5 @@
import * as fs from 'node:fs';
import * as stream from 'node:stream';
import * as util from 'node:util';
import * as stream from 'node:stream/promises';
import { Inject, Injectable } from '@nestjs/common';
import ipaddr from 'ipaddr.js';
import chalk from 'chalk';
@ -14,7 +13,6 @@ import { StatusError } from '@/misc/status-error.js';
import { LoggerService } from '@/core/LoggerService.js';
import type Logger from '@/logger.js';
const pipeline = util.promisify(stream.pipeline);
import { bindThis } from '@/decorators.js';
@Injectable()
@ -102,7 +100,7 @@ export class DownloadService {
});
try {
await pipeline(req, fs.createWriteStream(path));
await stream.pipeline(req, fs.createWriteStream(path));
} catch (e) {
if (e instanceof Got.HTTPError) {
throw new StatusError(`${e.response.statusCode} ${e.response.statusMessage}`, e.response.statusCode, e.response.statusMessage);
@ -129,7 +127,7 @@ export class DownloadService {
// write content at URL to temp file
await this.downloadUrl(url, path);
const text = await util.promisify(fs.readFile)(path, 'utf8');
const text = await fs.promises.readFile(path, 'utf8');
return text;
} finally {