fs#unlinkSync JavaScript Examples
The following examples show how to use
fs#unlinkSync.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: main.js From HinataMd with GNU General Public License v3.0 | 6 votes |
function clearTmp() {
const tmp = [tmpdir(), join(__dirname, './tmp')]
const filename = []
tmp.forEach(dirname => readdirSync(dirname).forEach(file => filename.push(join(dirname, file))))
return filename.map(file => {
const stats = statSync(file)
if (stats.isFile() && (Date.now() - stats.mtimeMs >= 1000 * 60 * 3)) return unlinkSync(file) // 3 minutes
return false
})
}
Example #2
Source File: owner-cleartmp.js From HinataMd with GNU General Public License v3.0 | 6 votes |
handler = async (m, { conn, usedPrefix: _p, __dirname, args }) => {
conn.reply(m.chat, 'Succes !', m)
const tmp = [tmpdir(), join(__dirname, '../tmp')]
const filename = []
tmp.forEach(dirname => readdirSync(dirname).forEach(file => filename.push(join(dirname, file))))
return filename.map(file => {
const stats = statSync(file)
unlinkSync(file)
})
}
Example #3
Source File: owner-df.js From HinataMd with GNU General Public License v3.0 | 6 votes |
handler = async (m, { conn, usedPrefix: _p, __dirname, args, text }) => {
let ar = Object.keys(plugins)
let ar1 = ar.map(v => v.replace('.js', ''))
if (!text) throw `uhm.. where the text?\n\nexample:\n${usedPrefix + command} info`
if (!ar1.includes(args[0])) return m.reply(`*?️ NOT FOUND!*\n==================================\n\n${ar1.map(v => ' ' + v).join`\n`}`)
const file = join(__dirname, '../plugins/' + args[0] + '.js')
unlinkSync(file)
conn.reply(m.chat, `Succes deleted "plugins/${args[0]}.js"`, m)
}
Example #4
Source File: tool-tts.js From HinataMd with GNU General Public License v3.0 | 6 votes |
function tts(text, lang = 'id') {
console.log(lang, text)
return new Promise((resolve, reject) => {
try {
let tts = gtts(lang)
let filePath = join(global.__dirname(import.meta.url), '../tmp', (1 * new Date) + '.wav')
tts.save(filePath, text, () => {
resolve(readFileSync(filePath))
unlinkSync(filePath)
})
} catch (e) { reject(e) }
})
}
Example #5
Source File: outbox-store.js From medusa with MIT License | 6 votes |
async flushFile(filePath, flushOperation) {
const now = `${Date.now()}-${process.pid}`
let success = false
let contents = ``
try {
if (!existsSync(filePath)) {
return true
}
// Unique temporary file name across multiple concurrent Medusa instances
const newPath = `${this.bufferFilePath}-${now}`
renameSync(filePath, newPath)
contents = readFileSync(newPath, `utf8`)
unlinkSync(newPath)
// There is still a chance process dies while sending data and some events are lost
// This will be ok for now, however
success = await flushOperation(contents)
} catch (e) {
if (isTruthy(MEDUSA_TELEMETRY_VERBOSE)) {
console.error("Failed to perform file flush", e)
}
} finally {
// if sending fails, we write the data back to the log
if (!success) {
if (isTruthy(MEDUSA_TELEMETRY_VERBOSE)) {
console.error(
"File flush did not succeed - writing back to file",
success
)
}
this.appendToBuffer(contents)
}
}
return true
}
Example #6
Source File: nulis-hartatahta..js From HinataMd with GNU General Public License v3.0 | 5 votes |
function ht(text = '') {
return new Promise((resolve, reject) => {
let img = join(aesthetic, pickRandom(readdirSync(aesthetic)))
let font = join(_font, 'Roboto-Black.ttf')
let w = 1024
let h = w
let s = w + 'x' + h
let xF = `(${noise('X', 2, w, 1)}+${noise('Y', 1, h, 1)})/2+128`
let yF = `((${pickRandom(['', '-'])}${45 * w / 2048}*${pickRandom(['sin', 'cos'])}(X/${w}*4*PI))+${noise('X', 5, w, 0.8)}+${noise('Y', 2, h, 1)})/1.7+128`
let fsize = 320 / 2048 * w
let lh = 1.5
let format = ''
let layers = [
`[v:0]scale=${s}${format}[im]`,
textArgs('HARTA', 'black', 'white', fsize, font, '(w-text_w)/2', `(h-text_h)/2-(text_h*${lh})`, w, h) + format + '[top]',
textArgs('TAHTA', 'black', 'white', fsize, font, '(w-text_w)/2', `(h-text_h)/2`, w, h) + format + '[mid]',
textArgs(text, 'black', 'white', fsize, font, '(w-text_w)/2', `(h-text_h)/2+(text_h*${lh})`, w, h) + format + '[bot]',
'[top][mid]blend=all_mode=addition[con]',
'[con][bot]blend=all_mode=addition[txt]',
`nullsrc=s=${s},geq='r=${xF}:g=${xF}:b=${xF}'[dx]`,
`nullsrc=s=${s},geq='r=${yF}:g=${yF}:b=${yF}'[dy]`,
'[txt][dx][dy]displace[wa]',
'[im][wa]blend=all_mode=multiply:all_opacity=1'
]
let o = 1 * new Date + '_harta_tahta.png'
o = join(tmp, o)
let args = [
'-y',
'-i', img,
'-filter_complex', layers.join(';'),
'-frames:v', '1',
o
]
spawn('ffmpeg', args)
.on('error', reject)
.on('close', () => {
try {
resolve(readFileSync(o))
unlinkSync(o)
} catch (e) {
reject(e)
}
})
//.stderr.on('data', a => console.log(a+''))
})
}
Example #7
Source File: serverAnalyzer.js From asymptoteWebApplication with GNU Lesser General Public License v3.0 | 5 votes |
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Resolver core function
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function asyRunManager(req, res, next, option) {
const asyArgs = ['-noV', '-outpipe', '2', '-noglobalread', '-f', option.outformat, option.codeFile];
const chProcOption = {
cwd: option.cwd,
}
const htmlFileExists = existsSync(req.body.htmlFile);
// if (req.body.reqType === "download" && option.outformat === "html" && htmlFileExists) {
// res.send({
// responseType: FLAGS.SUCCESS.ASY_OUTPUT_CREATED,
// isUpdated: !req.body.isUpdated
// });
// return;
// }
if (htmlFileExists) {
unlinkSync(req.body.htmlFile);
}
let stderrData = "", stdoutData = "";
const chProcHandler = spawn('asy', asyArgs, chProcOption);
setTimeout(() => {
chProcHandler.kill("SIGTERM");
}, serverTimeout)
// ------------------------------- onError
chProcHandler.on('error', (err) => {
const errResObject = errResCreator(FLAGS.FAILURE.PROCESS_SPAWN_ERR, err);
chProcHandler.kill();
res.send(errResObject);
});
// ------------------------------- onData
chProcHandler.stderr.on('data', (chunk) => {stderrData += chunk.toString()});
chProcHandler.stdout.on('data', (chunk) => {stdoutData += chunk.toString()});
// ------------------------------- onClose
chProcHandler.on('close', () => {});
// ------------------------------- onExit
chProcHandler.on('exit', (code, signal) => {
if (code === null) {
(signal === "SIGTERM") ? res.send(errResCreator(FLAGS.FAILURE.PROCESS_TIMEDOUT_ERR)) :
res.send(errResCreator(FLAGS.FAILURE.PROCESS_TERMINATED_ERR));
} else if (code !== 0) {
res.send({
...errResCreator(FLAGS.FAILURE.ASY_CODE_COMPILE_ERR),
stderr: stderrData,
stdout: stdoutData,
isUpdated: false
});
} else {
process.nextTick(() => {
const outputFilePath = req.body.usrAbsDirPath + "/" + req.body.codeFilename + "." + option.outformat;
if (existsSync(outputFilePath)) {
res.send({
responseType: FLAGS.SUCCESS.ASY_OUTPUT_CREATED,
stderr: stderrData,
stdout: stdoutData,
isUpdated: !req.body.isUpdated,
path: (option.outformat === "html")? req.body.usrRelDirPath
+ "/" + req.body.codeFilename + "." + option.outformat: ""
});
} else {
res.send({
responseType: FLAGS.SUCCESS.ASY_RUN_NO_OUTPUT,
stderr: stderrData,
stdout: stdoutData,
isUpdated: false
});
}
});
}
// console.log(`Code: ${code}\nSignal: ${signal}`);
});
}