Permalink
Browse files

Use flate2 compression for loading dumps.

  • Loading branch information...
1 parent 4e168d5 commit 266ff8928045c5dac7609cd9f355981911b0cea1 @trishume committed Jun 11, 2016
Showing with 20 additions and 10 deletions.
  1. +0 −2 .gitignore
  2. +1 −0 Cargo.toml
  3. BIN assets/default_newlines.packdump
  4. BIN assets/default_nonewlines.packdump
  5. +18 −8 src/dumps.rs
  6. +1 −0 src/lib.rs
View
@@ -1,4 +1,2 @@
target
Cargo.lock
-# Ignore the dumps for now until the format stabilizes
-assets/*
View
@@ -13,6 +13,7 @@ bitflags = "^0.4"
plist = "0.0.13"
rustc-serialize = "0.3"
bincode = "0.5"
+flate2 = "*"
# [profile.release]
# debug = true
Binary file not shown.
Binary file not shown.
View
@@ -1,9 +1,12 @@
use bincode::SizeLimit;
use bincode::rustc_serialize::*;
use std::fs::File;
-use std::io::BufReader;
+use std::io::{BufReader, BufWriter};
use package_set::PackageSet;
use std::path::Path;
+use flate2::write::ZlibEncoder;
+use flate2::read::ZlibDecoder;
+use flate2::Compression;
impl PackageSet {
/// Instantiates a new package set from a binary dump of
@@ -26,7 +29,7 @@ impl PackageSet {
/// Same as `load_defaults_nonewlines` but for parsing line strings with newlines at the end.
/// These are separate methods because thanks to linker garbage collection, only the serialized
- /// dumps for the method(s) you call will be included in the binary (each is ~1MB for now).
+ /// dumps for the method(s) you call will be included in the binary (each is ~200kb for now).
pub fn load_defaults_newlines() -> PackageSet {
let mut ps = Self::from_binary(include_bytes!("../assets/default_newlines.packdump"));
ps.link_syntaxes();
@@ -35,18 +38,25 @@ impl PackageSet {
pub fn dump_binary(&self) -> Vec<u8> {
assert!(!self.is_linked);
- encode(self, SizeLimit::Infinite).unwrap()
+ let mut v = Vec::new();
+ {
+ let mut encoder = ZlibEncoder::new(&mut v, Compression::Best);
+ encode_into(self, &mut encoder, SizeLimit::Infinite).unwrap();
+ }
+ v
}
pub fn dump_to_file<P: AsRef<Path>>(&self, path: P) -> EncodingResult<()> {
- let mut f = try!(File::create(path).map_err(EncodingError::IoError));
- encode_into(self, &mut f, SizeLimit::Infinite)
+ let f = BufWriter::new(try!(File::create(path).map_err(EncodingError::IoError)));
+ let mut encoder = ZlibEncoder::new(f, Compression::Best);
+ encode_into(self, &mut encoder, SizeLimit::Infinite)
}
/// Returns a fully loaded and linked package set from
/// a binary dump. Panics if the dump is invalid.
pub fn from_binary(v: &[u8]) -> PackageSet {
- let mut ps: PackageSet = decode(v).unwrap();
+ let mut decoder = ZlibDecoder::new(v);
+ let mut ps: PackageSet = decode_from(&mut decoder, SizeLimit::Infinite).unwrap();
ps.link_syntaxes();
ps
}
@@ -55,8 +65,8 @@ impl PackageSet {
/// a binary dump file.
pub fn from_dump_file<P: AsRef<Path>>(path: P) -> DecodingResult<PackageSet> {
let f = try!(File::open(path).map_err(DecodingError::IoError));
- let mut reader = BufReader::new(f);
- decode_from(&mut reader, SizeLimit::Infinite)
+ let mut decoder = ZlibDecoder::new(BufReader::new(f));
+ decode_from(&mut decoder, SizeLimit::Infinite)
}
}
View
@@ -9,6 +9,7 @@ extern crate bincode;
extern crate rustc_serialize;
#[macro_use]
extern crate bitflags;
+extern crate flate2;
pub mod syntax_definition;
pub mod yaml_load;
pub mod package_set;

0 comments on commit 266ff89

Please sign in to comment.