aboutsummaryrefslogtreecommitdiffstats
path: root/eth
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 /eth
parentee445a2ba4013f8b32e4e5386322babf022e5b81 (diff)
downloaddexon-9ba9fe818d252ee9770371f0ccad68e3d09fbf5c.tar.gz
dexon-9ba9fe818d252ee9770371f0ccad68e3d09fbf5c.tar.zst
dexon-9ba9fe818d252ee9770371f0ccad68e3d09fbf5c.zip
cmd/utils, eth: Add gzip support for chain dump and restore
Diffstat (limited to 'eth')
-rw-r--r--eth/api.go19
1 files changed, 17 insertions, 2 deletions
diff --git a/eth/api.go b/eth/api.go
index a86ed95cf..0a1d097e3 100644
--- a/eth/api.go
+++ b/eth/api.go
@@ -18,6 +18,7 @@ package eth
import (
"bytes"
+ "compress/gzip"
"errors"
"fmt"
"io"
@@ -25,6 +26,7 @@ import (
"math/big"
"os"
"runtime"
+ "strings"
"time"
"github.com/ethereum/ethash"
@@ -217,8 +219,14 @@ func (api *PrivateAdminAPI) ExportChain(file string) (bool, error) {
}
defer out.Close()
+ var writer io.Writer = out
+ if strings.HasSuffix(file, ".gz") {
+ writer = gzip.NewWriter(writer)
+ defer writer.(*gzip.Writer).Close()
+ }
+
// Export the blockchain
- if err := api.eth.BlockChain().Export(out); err != nil {
+ if err := api.eth.BlockChain().Export(writer); err != nil {
return false, err
}
return true, nil
@@ -243,8 +251,15 @@ func (api *PrivateAdminAPI) ImportChain(file string) (bool, error) {
}
defer in.Close()
+ var reader io.Reader = in
+ if strings.HasSuffix(file, ".gz") {
+ if reader, err = gzip.NewReader(reader); err != nil {
+ return false, err
+ }
+ }
+
// Run actual the import in pre-configured batches
- stream := rlp.NewStream(in, 0)
+ stream := rlp.NewStream(reader, 0)
blocks, index := make([]*types.Block, 0, 2500), 0
for batch := 0; ; batch++ {