compress-picture-js
Version:
36 lines (35 loc) • 944 B
JavaScript
import fs from 'fs';
import * as path from 'path';
// DefaultFileMode 默认文件权限
export const DefaultFileMode = '0744';
// ReadFileSync 读取文件
export function ReadFileSync(path) {
return fs.readFileSync(path, { flag: 'r' });
}
// WriteFileSync 写文件
export function WriteFileSync(path, data) {
fs.writeFileSync(path, new DataView(data));
}
// CreateDirSync 创建目录
export function CreateDirSync(dir) {
fs.mkdirSync(dir, {
mode: DefaultFileMode,
recursive: true,
});
}
// CreateDirSyncFromFilename 创建目录;来自文件
export function CreateDirSyncFromFilename(filename) {
let dir = path.dirname(filename);
if (ExistsSync(dir)) {
return;
}
CreateDirSync(dir);
}
// ExistsSync 检查文件是否存在
export function ExistsSync(path) {
return fs.existsSync(path);
}
// UnlinkSync 移除文件
export function UnlinkSync(path) {
fs.unlinkSync(path);
}