-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache.js
executable file
·46 lines (46 loc) · 1.13 KB
/
cache.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#! /usr/bin/env node
// head
var X0F = require('fs')
, X0P = require('stream').Transform
, x0p = new X0P({objectMode: true})
, x0s = __dirname + '/cache.json'
// body
x0p._transform = function processCacheRecord1(x1r) {
var x1f, x1p = this, x1b = false
, y1o = JSON.parse(new Buffer(x1r).toString())
function sendNoFileData100() {
x1p.push('{"0": {"exists": false}}')
X0F.unlink(x0s)
process.exit(0)
return
}
function collectAndSendFileData12(x12s) {
x1b = true
x1p.push(x12s)
return
}
function finishCaching13() {
(x1b) ? process.exit(0) : sendNoFileData100()
return
}
if (y1o[0].exists) {
x1f = X0F.createWriteStream(x0s)
x1f.write(JSON.stringify(y1o))
this.push(JSON.stringify(y1o))
}
else if (y1o[0].exists === false) sendNoFileData100()
else if (y1o[0].cache) {
x1f = X0F.createReadStream(x0s)
x1f.setEncoding('utf8')
x1f.on('error', sendNoFileData100).on('data', collectAndSendFileData12).on('end', finishCaching13)
}
else {
x1f = X0F.createWriteStream(x0s, {flags: 'a'})
x1f.write(JSON.stringify(y1o))
this.push(JSON.stringify(y1o))
}
return
}
process.stdin
.pipe(x0p)
.pipe(process.stdout)