aboutsummaryrefslogtreecommitdiff
path: root/util/featureWriterStream.js
diff options
context:
space:
mode:
authorNeil Fuller <nfuller@google.com>2021-06-10 16:23:35 +0100
committerNeil Fuller <nfuller@google.com>2021-06-11 11:15:25 +0100
commita742137af6b180c09cccaa37ab793c6715d38f03 (patch)
tree17dc4dd8808efc344fbcb1b4f2e87237a9b017c3 /util/featureWriterStream.js
parent671355f22a1368e27b8c588bfab35abf30aab0f0 (diff)
parent4e05cb681f519913cf847e4d1bf1621e759cb816 (diff)
downloadtimezone-boundary-builder-a742137af6b180c09cccaa37ab793c6715d38f03.tar.gz
Merge remote-tracking branch 'aosp/upstream-master'
Taking all upstream files as they are, i.e. git checkout aosp/upstream-master -- <file> Bug: 190733142 Test: Manual execution, etc. Change-Id: Ifdb4f9cd29d379b67381f1d1e66ef767041edd66
Diffstat (limited to 'util/featureWriterStream.js')
-rw-r--r--util/featureWriterStream.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/util/featureWriterStream.js b/util/featureWriterStream.js
new file mode 100644
index 0000000..7f0e7b8
--- /dev/null
+++ b/util/featureWriterStream.js
@@ -0,0 +1,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