Skip to content

Commit a5518a8

Browse files
committed
Compress snapshot files
Fix: #220
1 parent c006836 commit a5518a8

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

sync/src/snapshot/service.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use ctypes::H256;
2525

2626
use kvdb::KeyValueDB;
2727
use rlp::{decode as rlp_decode, RlpStream};
28+
use snap;
2829
use trie::{Node, OwnedNode};
2930

3031
use super::error::Error;
@@ -91,6 +92,7 @@ fn write_snapshot(db: Arc<KeyValueDB>, path: PathBuf, root: &H256) -> Result<(),
9192

9293
{
9394
let mut file = File::create(path.join("head"))?;
95+
let mut snappy = snap::Writer::new(file);
9496

9597
let mut stream = RlpStream::new();
9698
stream.begin_unbounded_list();
@@ -101,12 +103,14 @@ fn write_snapshot(db: Arc<KeyValueDB>, path: PathBuf, root: &H256) -> Result<(),
101103
}
102104
stream.complete_unbounded_list();
103105

104-
file.write(&stream.drain())?;
106+
snappy.write(&stream.drain())?;
105107
}
106108

107109
for (grandchild, _) in &grandchildren {
108110
let nodes = enumerate_subtree(&db, grandchild)?;
109111
let mut file = File::create(path.join(format!("{:x}", grandchild)))?;
112+
let mut snappy = snap::Writer::new(file);
113+
110114
let mut stream = RlpStream::new();
111115
stream.begin_unbounded_list();
112116
for (key, value) in nodes {
@@ -115,7 +119,8 @@ fn write_snapshot(db: Arc<KeyValueDB>, path: PathBuf, root: &H256) -> Result<(),
115119
stream.append(&value);
116120
}
117121
stream.complete_unbounded_list();
118-
file.write(&stream.drain())?;
122+
123+
snappy.write(&stream.drain())?;
119124
}
120125

121126
Ok(())

0 commit comments

Comments
 (0)