diff options
author | Neil Fuller <nfuller@google.com> | 2021-06-10 16:23:35 +0100 |
---|---|---|
committer | Neil Fuller <nfuller@google.com> | 2021-06-11 11:15:25 +0100 |
commit | a742137af6b180c09cccaa37ab793c6715d38f03 (patch) | |
tree | 17dc4dd8808efc344fbcb1b4f2e87237a9b017c3 /util/featureWriterStream.js | |
parent | 671355f22a1368e27b8c588bfab35abf30aab0f0 (diff) | |
parent | 4e05cb681f519913cf847e4d1bf1621e759cb816 (diff) | |
download | timezone-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.js | 25 |
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 |