Created
August 17, 2017 04:50
-
-
Save tuncatunc/35e5449905159928e718d82c06bc66da to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
const JSONStream = require('JSONStream'); | |
var es = require('event-stream'); | |
const filePath = './location-history.json' | |
const fileOutputPath = './transform-location-history.js' | |
const fileStream = fs.createReadStream(filePath); | |
const fileOutputStream = fs.createWriteStream(fileOutputPath) | |
let index = 0; | |
const transformer = (data) => { | |
const location = { | |
latitude: data.latitudeE7 / 10000000, | |
longitude: data.longitudeE7 / 10000000 | |
}; | |
let result = JSON.stringify(location) + ','; | |
if (index === 0) { | |
result = 'const locationHistory = [' + result | |
} | |
index++; | |
if (index < 100) | |
fileOutputStream.write(result); | |
} | |
const end = () => { | |
const finish = ']; export default locationHistory\n' | |
fileOutputStream.write(finish, () => { | |
fileOutputStream.close() | |
}) | |
console.log(`${index} objects are written to file`) | |
} | |
fileStream | |
.pipe(JSONStream.parse('locations.*')) | |
.pipe(es.through(transformer, end)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment