Added saving to json.gz and csv.gz
This commit is contained in:
@@ -309,6 +309,10 @@ func main() {
|
|||||||
SaveToCsvFile(exportingData, keyMap, *outputPath, *fullExport)
|
SaveToCsvFile(exportingData, keyMap, *outputPath, *fullExport)
|
||||||
case ".json":
|
case ".json":
|
||||||
SaveToJSONFile(exportingData, keyMap, *outputPath, *fullExport)
|
SaveToJSONFile(exportingData, keyMap, *outputPath, *fullExport)
|
||||||
|
case ".csv.gz":
|
||||||
|
SaveToCsvGzFile(exportingData, keyMap, *outputPath, *fullExport)
|
||||||
|
case ".json.gz":
|
||||||
|
SaveToJSONGzFile(exportingData, keyMap, *outputPath, *fullExport)
|
||||||
default:
|
default:
|
||||||
log.Fatal("Incorrect file type")
|
log.Fatal("Incorrect file type")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"compress/gzip"
|
||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
@@ -101,3 +102,29 @@ func SaveToJSONFile(data []StatForTime, keyMap map[uint8]string, path string, fu
|
|||||||
|
|
||||||
SaveToJSONWriter(data, keyMap, jsonFile, fullExport)
|
SaveToJSONWriter(data, keyMap, jsonFile, fullExport)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SaveToCsvGzFile(data []StatForTime, keyMap map[uint8]string, path string, fullExport bool) {
|
||||||
|
jsonFile, err := os.Create(path)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
defer jsonFile.Close()
|
||||||
|
|
||||||
|
gzipWriter := gzip.NewWriter(jsonFile)
|
||||||
|
defer gzipWriter.Close()
|
||||||
|
|
||||||
|
SaveToCsvWriter(data, keyMap, gzipWriter, fullExport)
|
||||||
|
}
|
||||||
|
|
||||||
|
func SaveToJSONGzFile(data []StatForTime, keyMap map[uint8]string, path string, fullExport bool) {
|
||||||
|
jsonFile, err := os.Create(path)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
defer jsonFile.Close()
|
||||||
|
|
||||||
|
gzipWriter := gzip.NewWriter(jsonFile)
|
||||||
|
defer gzipWriter.Close()
|
||||||
|
|
||||||
|
SaveToJSONWriter(data, keyMap, gzipWriter, fullExport)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user