blob: 7f0e7b81886540a622e150234cf3df34bb48d8b4 (
plain)
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
|
const fs = require('fs')
class FeatureWriterStream {
constructor (file) {
this.file = file
this.stream = fs.createWriteStream(file)
this.stream.write('{"type":"FeatureCollection","features":[')
this.numFeatures = 0
}
add (stringifiedFeature) {
if (this.numFeatures > 0) {
this.stream.write(',')
}
this.stream.write(stringifiedFeature)
this.numFeatures++
}
end (cb) {
console.log(`Closing out file ${this.file}`)
this.stream.end(']}', cb)
}
}
module.exports = FeatureWriterStream
|