Node.js-14-Cookbook/Chapter03/working-with-files/asynchronous-file-operations/null-byte-remover-sync-with-progress-dots.js
2017-07-31 11:33:31 +05:30

16 lines
421 B
JavaScript

'use strict'
setInterval(() => process.stdout.write('.'), 10).unref()
const fs = require('fs')
const path = require('path')
const cwd = process.cwd()
const bytes = fs.readFileSync(path.join(cwd, 'file.dat'))
const clean = bytes.filter(n => n)
fs.writeFileSync(path.join(cwd, 'clean.dat'), clean)
fs.appendFileSync(
path.join(cwd, 'log.txt'),
(new Date) + ' ' + (bytes.length - clean.length) + ' bytes removed\n'
)