mirror of
https://github.com/aclindsa/moneygo.git
synced 2024-12-27 07:52:28 -05:00
gnucash: Support directly importing gzipped files
This commit is contained in:
parent
69bbd3db62
commit
cd9ad1d4d7
25
gnucash.go
25
gnucash.go
@ -1,6 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
|
"compress/gzip"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -288,7 +290,28 @@ func GnucashImportHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
gnucashImport, err := ImportGnucash(part)
|
bufread := bufio.NewReader(part)
|
||||||
|
gzHeader, err := bufread.Peek(2)
|
||||||
|
if err != nil {
|
||||||
|
WriteError(w, 999 /*Internal Error*/)
|
||||||
|
log.Print(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Does this look like a gzipped file?
|
||||||
|
var gnucashImport *GnucashImport
|
||||||
|
if gzHeader[0] == 0x1f && gzHeader[1] == 0x8b {
|
||||||
|
gzr, err := gzip.NewReader(bufread)
|
||||||
|
if err != nil {
|
||||||
|
WriteError(w, 999 /*Internal Error*/)
|
||||||
|
log.Print(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
gnucashImport, err = ImportGnucash(gzr)
|
||||||
|
} else {
|
||||||
|
gnucashImport, err = ImportGnucash(bufread)
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
WriteError(w, 3 /*Invalid Request*/)
|
WriteError(w, 3 /*Invalid Request*/)
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user