const { promisify } = require('util'); const jsonfile = require('jsonfile'); const logger = require('log4js').getLogger(); const lz77 = require('lz77'); var lzw = require('json-lzw'); logger.level = 'trace'; const file = '../src/work/stations.json'; const outFile = '../src/work/stationsMap.json'; const compressed = '../src/work/stations.lzw'; const readFile = promisify(jsonfile.readFile); const writeFile = promisify(jsonfile.writeFile); function doConvert(obj) { const tempArray = []; for(const item of obj.locations) if ((item.lat !== 0) && (item.lon !== 0)) // logger.debug(item.name); tempArray.push({ 'crs':item.crs, 'name':item.name, 'lat':item.lat, 'long':item.lon }); // const locMap = new Map(tempArray); // logger.debug(locMap); const test = lz77.compress(JSON.stringify(tempArray), { 'minStringLength':3 }); console.log(test); writeFile(outFile, tempArray) .then( () => { logger.debug('Saved...'); } ) .catch(err => { logger.error('Json failed to save'); logger.warn(err); }); } readFile(file) .then(obj => { logger.info('json loaded....'); doConvert(obj); }) .catch(err => { logger.error('Json failed to load'); logger.warn(err); }); /* jsonfile.readFile(file, (err, obj) => { if (err) { logger.error('Json failed to load'); logger.warn(err); } else { logger.info('Json loaded...'); doConvert(obj); } }); */