osrm-backend/traffic_updater/go/snappy_command/snappy_command.go
Xun(Perry) Liu a3eb24a0fc Feature/optimize traffic convertor (#41)
* feat: Optimize output of wayid2nodeids format, use delta format to comparess data

Issues: https://github.com/Telenav/osrm-backend/issues/31

* feat: Implement logic to compress/decompress file to snappy.

issues: https://github.com/Telenav/osrm-backend/issues/31

* feat: Modify osrm speed table generator to support snappy compression format.

issues: https://github.com/Telenav/osrm-backend/issues/31

* feat: Fix bug during conversion

* feat: Adjust traffic updater's logic to improve performance.

* feat: Adjust traffic updater's logic to improve performance.

issues: https://github.com/Telenav/osrm-backend/pull/39

* feat: Refine the code for osrm_traffic_updater.

issues: https://github.com/Telenav/osrm-backend/issues/31

* fix: fix dead lock in the code.

* fix: optimize performance with new architecture.
issues: https://github.com/Telenav/osrm-backend/issues/31

* fix: revert way id generator to original solution

* fix: Use string to pass between different components
issues: https://github.com/Telenav/osrm-backend/issues/31

* fix: update unit test for latest changes
issues: https://github.com/Telenav/osrm-backend/issues/31

* fix: remove useless printf

* fix: update unit test for osrm_traffic_updater.go

* fix: fix the misunderstanding with requirement.  Traffic server generates -wayid indicate for traffic flow on reverse direction.
issues: https://github.com/Telenav/osrm-backend/issues/31
2019-07-17 09:11:38 +08:00

65 lines
1.2 KiB
Go

package main
import (
"flag"
"strings"
"fmt"
"os"
"io"
"github.com/golang/snappy"
)
const snappySuffix string = ".snappy"
var flags struct {
input string
output string
suffix string
}
func init() {
flag.StringVar(&flags.input, "i", "", "Input file.")
flag.StringVar(&flags.output, "o", "", "Output file.")
}
func main() {
flag.Parse()
inputCompressed := strings.HasSuffix(flags.input, snappySuffix)
outputCompressed := strings.HasSuffix(flags.output, snappySuffix)
if inputCompressed == outputCompressed {
fmt.Printf("Error. Input and output must have one with .snappy suffix and one without.\n")
return
}
fi, err1 := os.Open(flags.input)
if err1 != nil {
fmt.Printf("Open input file failed.\n")
return
}
defer fi.Close()
fo, err2 := os.OpenFile(flags.output, os.O_RDWR|os.O_CREATE, 0755)
if err2 != nil {
fmt.Printf("Open output file failed.\n")
return
}
defer fo.Close()
defer fo.Sync()
buf := make([]byte, 128 * 1024)
if inputCompressed {
_, err := io.CopyBuffer(fo, snappy.NewReader(fi), buf)
if err != nil {
fmt.Printf("Decompression failed\n")
}
} else {
_, err := io.CopyBuffer(snappy.NewWriter(fo), fi, buf)
if err != nil {
fmt.Printf("Compression failed\n")
}
}
}