diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2017-06-08 14:10:36 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2017-06-20 07:11:29 -0700 |
| commit | a4024c58e1e5c92cfe3ed39ed9f5b96f3f38122e (patch) | |
| tree | 2c29cfb9741ad811d86780469eb4c570158fe216 /src/libflate | |
| parent | 380100c568c1c390c837caf98338d07c4d8a0462 (diff) | |
| download | rust-a4024c58e1e5c92cfe3ed39ed9f5b96f3f38122e.tar.gz rust-a4024c58e1e5c92cfe3ed39ed9f5b96f3f38122e.zip | |
Remove the in-tree `flate` crate
A long time coming this commit removes the `flate` crate in favor of the `flate2` crate on crates.io. The functionality in `flate2` originally flowered out of `flate` itself and is additionally the namesake for the crate. This will leave a gap in the naming (there's not `flate` crate), which will likely cause a particle collapse of some form somewhere.
Diffstat (limited to 'src/libflate')
| -rw-r--r-- | src/libflate/Cargo.toml | 14 | ||||
| -rw-r--r-- | src/libflate/build.rs | 18 | ||||
| -rw-r--r-- | src/libflate/lib.rs | 166 |
3 files changed, 0 insertions, 198 deletions
diff --git a/src/libflate/Cargo.toml b/src/libflate/Cargo.toml deleted file mode 100644 index e5c611460f7..00000000000 --- a/src/libflate/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -authors = ["The Rust Project Developers"] -name = "flate" -version = "0.0.0" -build = "build.rs" - -[lib] -name = "flate" -path = "lib.rs" -crate-type = ["dylib"] - -[build-dependencies] -build_helper = { path = "../build_helper" } -gcc = "0.3.50" diff --git a/src/libflate/build.rs b/src/libflate/build.rs deleted file mode 100644 index 78d2ef1e37d..00000000000 --- a/src/libflate/build.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -extern crate gcc; - -fn main() { - println!("cargo:rerun-if-changed=../rt/miniz.c"); - gcc::Config::new() - .file("../rt/miniz.c") - .compile("libminiz.a"); -} diff --git a/src/libflate/lib.rs b/src/libflate/lib.rs deleted file mode 100644 index bc34e7810be..00000000000 --- a/src/libflate/lib.rs +++ /dev/null @@ -1,166 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Simple [DEFLATE][def]-based compression. This is a wrapper around the -//! [`miniz`][mz] library, which is a one-file pure-C implementation of zlib. -//! -//! [def]: https://en.wikipedia.org/wiki/DEFLATE -//! [mz]: https://code.google.com/p/miniz/ - -#![crate_name = "flate"] -#![crate_type = "rlib"] -#![crate_type = "dylib"] -#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", - html_favicon_url = "https://doc.rust-lang.org/favicon.ico", - html_root_url = "https://doc.rust-lang.org/nightly/", - test(attr(deny(warnings))))] -#![deny(warnings)] - -#![feature(libc)] -#![feature(unique)] -#![cfg_attr(test, feature(rand))] - -extern crate libc; - -use libc::{c_int, c_void, size_t}; -use std::fmt; -use std::ops::Deref; -use std::ptr::Unique; -use std::slice; - -#[derive(Clone, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct Error { - _unused: (), -} - -impl Error { - fn new() -> Error { - Error { _unused: () } - } -} - -impl fmt::Debug for Error { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - "decompression error".fmt(f) - } -} - -pub struct Bytes { - ptr: Unique<u8>, - len: usize, -} - -impl Deref for Bytes { - type Target = [u8]; - fn deref(&self) -> &[u8] { - unsafe { slice::from_raw_parts(self.ptr.as_ptr(), self.len) } - } -} - -impl Drop for Bytes { - fn drop(&mut self) { - unsafe { - libc::free(self.ptr.as_ptr() as *mut _); - } - } -} - -extern "C" { - /// Raw miniz compression function. - fn tdefl_compress_mem_to_heap(psrc_buf: *const c_void, - src_buf_len: size_t, - pout_len: *mut size_t, - flags: c_int) - -> *mut c_void; - - /// Raw miniz decompression function. - fn tinfl_decompress_mem_to_heap(psrc_buf: *const c_void, - src_buf_len: size_t, - pout_len: *mut size_t, - flags: c_int) - -> *mut c_void; -} - -const LZ_FAST: c_int = 0x01; // LZ with 1 probe, "fast" -const TDEFL_GREEDY_PARSING_FLAG: c_int = 0x04000; // fast greedy parsing instead of lazy parsing - -/// Compress a buffer without writing any sort of header on the output. Fast -/// compression is used because it is almost twice as fast as default -/// compression and the compression ratio is only marginally worse. -pub fn deflate_bytes(bytes: &[u8]) -> Bytes { - let flags = LZ_FAST | TDEFL_GREEDY_PARSING_FLAG; - unsafe { - let mut outsz: size_t = 0; - let res = tdefl_compress_mem_to_heap(bytes.as_ptr() as *const _, - bytes.len() as size_t, - &mut outsz, - flags); - assert!(!res.is_null()); - Bytes { - ptr: Unique::new(res as *mut u8), - len: outsz as usize, - } - } -} - -/// Decompress a buffer without parsing any sort of header on the input. -pub fn inflate_bytes(bytes: &[u8]) -> Result<Bytes, Error> { - let flags = 0; - unsafe { - let mut outsz: size_t = 0; - let res = tinfl_decompress_mem_to_heap(bytes.as_ptr() as *const _, - bytes.len() as size_t, - &mut outsz, - flags); - if !res.is_null() { - Ok(Bytes { - ptr: Unique::new(res as *mut u8), - len: outsz as usize, - }) - } else { - Err(Error::new()) - } - } -} - -#[cfg(test)] -mod tests { - #![allow(deprecated)] - use super::{deflate_bytes, inflate_bytes}; - use std::__rand::{Rng, thread_rng}; - - #[test] - fn test_flate_round_trip() { - let mut r = thread_rng(); - let mut words = vec![]; - for _ in 0..20 { - let range = r.gen_range(1, 10); - let v = r.gen_iter::<u8>().take(range).collect::<Vec<u8>>(); - words.push(v); - } - for _ in 0..20 { - let mut input = vec![]; - for _ in 0..2000 { - input.extend_from_slice(r.choose(&words).unwrap()); - } - let cmp = deflate_bytes(&input); - let out = inflate_bytes(&cmp).unwrap(); - assert_eq!(&*input, &*out); - } - } - - #[test] - fn test_zlib_flate() { - let bytes = vec![1, 2, 3, 4, 5]; - let deflated = deflate_bytes(&bytes); - let inflated = inflate_bytes(&deflated).unwrap(); - assert_eq!(&*inflated, &*bytes); - } -} |
