UNPKG

@diyaner/ding

Version:

dingiyan常用ts/js工具

95 lines (94 loc) 2.88 kB
/// <reference types="node" /> /// <reference types="node" /> /// <reference types="node" /> import * as fs from "fs"; import { Stream } from "stream"; /** *文件转换为base64,从本地path读取文件。 * * @param {*} filePath * @return {Promise} string | null */ export declare function file_to_base64(filePath: string): string; /** *可读流转换为base64 * * @param {Stream} stream * @return {*} */ export declare function stream_to_base64(stream: Stream): Promise<string>; /** *stream转换为buffer对象 * * @export * @param {Stream} stream * @return {*} */ export declare function stream_to_buffer(stream: Stream): Promise<Buffer>; /** *buffer转换为stream对象 【暂未验证本方法】 * * @export * @param {Buffer} buffer * @return {*} */ export declare function buffer_to_stream(buffer: Buffer): Stream; /** base64 to buffer */ export declare function base64_to_buffer(base64: string): Buffer; export declare function buffer_to_base64(buf: Buffer): string; /** base64 to stream */ export declare function base64_to_stream(base64: string): Stream; /** *stream 可读流写入服务器文件的封装方法 * * @export * @param {fs.ReadStream} readStream 可读流 * @param {string} writeFilePath 写入文件的路径 * @return {*} {(Promise<true | any>)} */ export declare function streamWriteToFile(readStream: fs.ReadStream, writeFilePath: string): Promise<true | any>; /** *获取一个文件夹路径下所有文件的list * * @param {string} dirPath 文件夹路径 * @returns [filepath1,filepath2] */ export declare function getFilesListByDir(dirPath: string): string[]; /** *获取一个文件夹路径下所有文件夹list * * @param {string} dirPath 文件夹路径 * @returns [filepath1,filepath2] */ export declare function getDirListByDir(dirPath: string): string[]; /** * *删除一个目录,包含其下的文件和子文件夹 * * @param {*} p 要操作的文件夹dir path * @param {boolean} [isDelDir=true] 是否要删除根文件夹,默认true */ export declare function delDir(p: string, isDelDir?: boolean): void; /** *创建文件夹,可递归创建 * * @export * @param {string} dirpath 文件夹path路径 * @deprecated 弃用,请使用fs.mkdirSync 直接调用,传入recursive:true参数即可。 */ export declare function mkdirs(dirpath: string): void; /** 复制一个文件夹 */ export declare function copyDir(src: string, dest: string): boolean; declare const _default: { file_to_base64: typeof file_to_base64; stream_to_base64: typeof stream_to_base64; stream_to_buffer: typeof stream_to_buffer; buffer_to_stream: typeof buffer_to_stream; getFilesListByDir: typeof getFilesListByDir; getDirListByDir: typeof getDirListByDir; delDir: typeof delDir; mkdirs: typeof mkdirs; copyDir: typeof copyDir; }; export default _default;