aboutsummaryrefslogtreecommitdiff
path: root/util/featureWriterStream.js
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-05-10 07:23:31 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-05-10 07:23:31 +0000
commit455e0f5882615111849ab934fdb6ebfdaea1ad2c (patch)
tree99024a2bbbd3b3b16d007ab57ebf8052f0d49956 /util/featureWriterStream.js
parentb90502f6b7b8f045e38dfb88bf23bf26f7a7a072 (diff)
parentf0df97945b4fdddd066170b120f192941b8d7fbf (diff)
downloadtimezone-boundary-builder-android13-mainline-os-statsd-release.tar.gz
Change-Id: I5713aa596c36ea10726c60b0fc74716c6ab7cd06
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