mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 01:07:15 +03:00
mononoke: rename Context to DecompressContext
Summary: We are going to add CompressContext in the next diff Reviewed By: farnz Differential Revision: D8236761 fbshipit-source-id: 0df55b9bc5e9fd78ac8c060576513c1216641ead
This commit is contained in:
parent
3c46a1d9c3
commit
e2efcd5396
@ -34,22 +34,22 @@ pub enum ErrorKind {
|
|||||||
#[fail(display = "Compression failed")] LZ4CompressFailed,
|
#[fail(display = "Compression failed")] LZ4CompressFailed,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrapper for the lz4 library context
|
// Wrapper for the lz4 library decompress context
|
||||||
struct Context(*mut LZ4StreamDecode);
|
struct DecompressContext(*mut LZ4StreamDecode);
|
||||||
impl Context {
|
impl DecompressContext {
|
||||||
// Allocate a context; fails if allocation fails
|
// Allocate a context; fails if allocation fails
|
||||||
fn new() -> Result<Self, &'static str> {
|
fn new() -> Result<Self, &'static str> {
|
||||||
let ctx = unsafe { LZ4_createStreamDecode() };
|
let ctx = unsafe { LZ4_createStreamDecode() };
|
||||||
if ctx.is_null() {
|
if ctx.is_null() {
|
||||||
Err("failed to create LZ4 context")
|
Err("failed to create LZ4 decompress context")
|
||||||
} else {
|
} else {
|
||||||
Ok(Context(ctx))
|
Ok(DecompressContext(ctx))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure C resources for context get freed.
|
// Make sure C resources for context get freed.
|
||||||
impl Drop for Context {
|
impl Drop for DecompressContext {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if !self.0.is_null() {
|
if !self.0.is_null() {
|
||||||
unsafe { LZ4_freeStreamDecode(self.0) };
|
unsafe { LZ4_freeStreamDecode(self.0) };
|
||||||
@ -60,7 +60,7 @@ impl Drop for Context {
|
|||||||
|
|
||||||
// Decompress a raw lz4 block
|
// Decompress a raw lz4 block
|
||||||
fn decompress_block(i: &[u8], out: &mut Vec<u8>) -> Result<usize, String> {
|
fn decompress_block(i: &[u8], out: &mut Vec<u8>) -> Result<usize, String> {
|
||||||
let ctx = Context::new()?;
|
let ctx = DecompressContext::new()?;
|
||||||
unsafe {
|
unsafe {
|
||||||
let ret = LZ4_decompress_safe_continue(
|
let ret = LZ4_decompress_safe_continue(
|
||||||
ctx.0,
|
ctx.0,
|
||||||
|
Loading…
Reference in New Issue
Block a user