Files
develop202-migu_video/utils/fileUtil.js
2025-09-09 09:59:17 +08:00

33 lines
728 B
JavaScript

import fs from "fs"
function createFile(filePath) {
if (!fs.existsSync(filePath)) {
writeFile(filePath, "")
}
}
function writeFile(filePath, content) {
fs.writeFile(filePath, content, error => {
if (error) {
throw new Error(`${filePath}:写入${content}失败`)
}
})
}
function appendFile(filePath, content) {
fs.appendFile(filePath, content, error => {
if (error) {
throw new Error(`${filePath}:追加${content}失败`)
}
})
}
function appendFileSync(filePath, content) {
fs.appendFileSync(filePath, content, error => {
if (error) {
throw new Error(`${filePath}:同步追加${content}失败`)
}
})
}
export { createFile, writeFile, appendFile, appendFileSync }