Skip to content

Commit

Permalink
Finally delete the entire raw module
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Feb 7, 2016
1 parent 40ff16c commit 42566e0
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 359 deletions.
10 changes: 10 additions & 0 deletions src/deflate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,16 @@ mod tests {
assert!(ret == real);
}

#[test]
fn drop_writes() {
let mut data = Vec::new();
EncoderWriter::new(&mut data, Default).write_all(b"foo").unwrap();
let mut r = DecoderReader::new(&data[..]);
let mut ret = Vec::new();
r.read_to_end(&mut ret).unwrap();
assert!(ret == b"foo");
}

#[test]
fn total_in() {
let mut real = Vec::new();
Expand Down
27 changes: 12 additions & 15 deletions src/gz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use std::ffi::CString;
use std::io::prelude::*;
use std::io;

use Compression;
use {Compression, Compress};
use bufreader::BufReader;
use crc::{CrcReader, Crc};
use deflate;
use raw;
use zio;

static FHCRC: u8 = 1 << 1;
static FEXTRA: u8 = 1 << 2;
Expand All @@ -24,7 +24,7 @@ static FCOMMENT: u8 = 1 << 4;
/// This structure exposes a `Write` interface that will emit compressed data
/// to the underlying writer `W`.
pub struct EncoderWriter<W: Write> {
inner: raw::EncoderWriter<W>,
inner: zio::Writer<W, Compress>,
crc: Crc,
header: Vec<u8>,
}
Expand Down Expand Up @@ -130,10 +130,7 @@ impl Builder {
/// written out to the supplied parameter `w`.
pub fn write<W: Write>(self, w: W, lvl: Compression) -> EncoderWriter<W> {
EncoderWriter {
inner: raw::EncoderWriter::new(w,
lvl,
true,
Vec::with_capacity(32 * 1024)),
inner: zio::Writer::new(w, Compress::new(lvl, false)),
crc: Crc::new(),
header: self.into_header(lvl),
}
Expand Down Expand Up @@ -230,15 +227,16 @@ impl<W: Write> EncoderWriter<W> {
/// Finish encoding this stream, returning the underlying writer once the
/// encoding is done.
pub fn finish(mut self) -> io::Result<W> {
self.do_finish()
try!(self.do_finish());
Ok(self.inner.take_inner().unwrap())
}

fn do_finish(&mut self) -> io::Result<W> {
fn do_finish(&mut self) -> io::Result<()> {
if self.header.len() != 0 {
try!(self.inner.write_all_raw(&self.header));
try!(self.inner.get_mut().unwrap().write_all(&self.header));
}
try!(self.inner.finish());
let mut inner = self.inner.take_inner();
let mut inner = self.inner.get_mut().unwrap();
let (sum, amt) = (self.crc.sum() as u32, self.crc.amt_as_u32());
let buf = [(sum >> 0) as u8,
(sum >> 8) as u8,
Expand All @@ -248,15 +246,14 @@ impl<W: Write> EncoderWriter<W> {
(amt >> 8) as u8,
(amt >> 16) as u8,
(amt >> 24) as u8];
try!(inner.write_all(&buf));
Ok(inner)
inner.write_all(&buf)
}
}

impl<W: Write> Write for EncoderWriter<W> {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
if self.header.len() != 0 {
try!(self.inner.write_all_raw(&self.header));
try!(self.inner.get_mut().unwrap().write_all(&self.header));
self.header.truncate(0);
}
let n = try!(self.inner.write(buf));
Expand All @@ -271,7 +268,7 @@ impl<W: Write> Write for EncoderWriter<W> {

impl<W: Write> Drop for EncoderWriter<W> {
fn drop(&mut self) {
if !self.inner.unwrapped() {
if self.inner.get_mut().is_some() {
let _ = self.do_finish();
}
}
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ mod ffi;
mod gz;
mod zio;
mod mem;
mod raw;
mod stream;
mod zlib;

Expand Down
Loading

0 comments on commit 42566e0

Please sign in to comment.