UNPKG

503 BJavaScriptView Raw
1'use strict';
2
3const fs = require('fs');
4const mkdirpsync = require('./mkdirpSync');
5const path = require('path');
6
7var writeLazySafeSync = (file_path, body) => {
8 try {
9 var data = fs.readFileSync(file_path, 'utf-8');
10 if(data == body)
11 return false;
12 } catch(err) { }
13
14 mkdirpsync(path.dirname(file_path));
15 var tmp_path = file_path + '.tmp';
16 fs.writeFileSync(tmp_path, body);
17 fs.renameSync(tmp_path, file_path);
18 return true;
19};
20
21module.exports = writeLazySafeSync;