Use promises API (#11351)
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import * as fs from 'node:fs';
|
||||
import * as crypto from 'node:crypto';
|
||||
import { join } from 'node:path';
|
||||
import * as stream from 'node:stream';
|
||||
import * as util from 'node:util';
|
||||
import * as stream from 'node:stream/promises';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { FSWatcher } from 'chokidar';
|
||||
import * as fileType from 'file-type';
|
||||
@@ -16,8 +15,6 @@ import { createTempDir } from '@/misc/create-temp.js';
|
||||
import { AiService } from '@/core/AiService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
|
||||
const pipeline = util.promisify(stream.pipeline);
|
||||
|
||||
export type FileInfo = {
|
||||
size: number;
|
||||
md5: string;
|
||||
@@ -371,8 +368,7 @@ export class FileInfoService {
|
||||
*/
|
||||
@bindThis
|
||||
public async getFileSize(path: string): Promise<number> {
|
||||
const getStat = util.promisify(fs.stat);
|
||||
return (await getStat(path)).size;
|
||||
return (await fs.promises.stat(path)).size;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -381,7 +377,7 @@ export class FileInfoService {
|
||||
@bindThis
|
||||
private async calcHash(path: string): Promise<string> {
|
||||
const hash = crypto.createHash('md5').setEncoding('hex');
|
||||
await pipeline(fs.createReadStream(path), hash);
|
||||
await stream.pipeline(fs.createReadStream(path), hash);
|
||||
return hash.read();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user