aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorNick Johnson <arachnid@notdot.net>2016-12-12 23:08:23 +0800
committerNick Johnson <arachnid@notdot.net>2016-12-14 16:59:55 +0800
commit9ba9fe818d252ee9770371f0ccad68e3d09fbf5c (patch)
tree8f58f1782ab274350257a5a5846867df66fba981 /cmd
parentee445a2ba4013f8b32e4e5386322babf022e5b81 (diff)
downloaddexon-9ba9fe818d252ee9770371f0ccad68e3d09fbf5c.tar
dexon-9ba9fe818d252ee9770371f0ccad68e3d09fbf5c.tar.gz
dexon-9ba9fe818d252ee9770371f0ccad68e3d09fbf5c.tar.bz2
dexon-9ba9fe818d252ee9770371f0ccad68e3d09fbf5c.tar.lz
dexon-9ba9fe818d252ee9770371f0ccad68e3d09fbf5c.tar.xz
dexon-9ba9fe818d252ee9770371f0ccad68e3d09fbf5c.tar.zst
dexon-9ba9fe818d252ee9770371f0ccad68e3d09fbf5c.zip
cmd/utils, eth: Add gzip support for chain dump and restore
Diffstat (limited to 'cmd')
-rw-r--r--cmd/utils/cmd.go31
1 files changed, 28 insertions, 3 deletions
diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go
index 584afc804..a56507e4d 100644
--- a/cmd/utils/cmd.go
+++ b/cmd/utils/cmd.go
@@ -18,12 +18,14 @@
package utils
import (
+ "compress/gzip"
"fmt"
"io"
"os"
"os/signal"
"regexp"
"runtime"
+ "strings"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
@@ -133,7 +135,15 @@ func ImportChain(chain *core.BlockChain, fn string) error {
return err
}
defer fh.Close()
- stream := rlp.NewStream(fh, 0)
+
+ var reader io.Reader = fh
+ if strings.HasSuffix(fn, ".gz") {
+ if reader, err = gzip.NewReader(reader); err != nil {
+ return err
+ }
+ }
+
+ stream := rlp.NewStream(reader, 0)
// Run actual the import.
blocks := make(types.Blocks, importBatchSize)
@@ -195,10 +205,18 @@ func ExportChain(blockchain *core.BlockChain, fn string) error {
return err
}
defer fh.Close()
- if err := blockchain.Export(fh); err != nil {
+
+ var writer io.Writer = fh
+ if strings.HasSuffix(fn, ".gz") {
+ writer = gzip.NewWriter(writer)
+ defer writer.(*gzip.Writer).Close()
+ }
+
+ if err := blockchain.Export(writer); err != nil {
return err
}
glog.Infoln("Exported blockchain to ", fn)
+
return nil
}
@@ -210,7 +228,14 @@ func ExportAppendChain(blockchain *core.BlockChain, fn string, first uint64, las
return err
}
defer fh.Close()
- if err := blockchain.ExportN(fh, first, last); err != nil {
+
+ var writer io.Writer = fh
+ if strings.HasSuffix(fn, ".gz") {
+ writer = gzip.NewWriter(writer)
+ defer writer.(*gzip.Writer).Close()
+ }
+
+ if err := blockchain.ExportN(writer, first, last); err != nil {
return err
}
glog.Infoln("Exported blockchain to ", fn)