Cleanup filter_out_stream implementation

This commit is contained in:
topjohnwu
2023-05-20 01:28:10 -07:00
parent 655f778171
commit f5aaff2b1e
6 changed files with 13 additions and 50 deletions

View File

@@ -20,14 +20,14 @@ uint64_t dyn_img_hdr::j64 = 0;
static void decompress(format_t type, int fd, const void *in, size_t size) {
auto ptr = get_decoder(type, make_unique<fd_channel>(fd));
ptr->write(in, size, true);
ptr->write(in, size);
}
static off_t compress(format_t type, int fd, const void *in, size_t size) {
auto prev = lseek(fd, 0, SEEK_CUR);
{
auto strm = get_encoder(type, make_unique<fd_channel>(fd));
strm->write(in, size, true);
strm->write(in, size);
}
auto now = lseek(fd, 0, SEEK_CUR);
return now - prev;

View File

@@ -195,9 +195,6 @@ public:
protected:
bool write_chunk(const void *buf, size_t len, bool final) override {
if (len == 0)
return true;
auto in = static_cast<const unsigned char *>(buf);
in_total += len;
@@ -514,7 +511,7 @@ public:
}
protected:
bool write_chunk(const void *buf, size_t len, bool final) override {
bool write_chunk(const void *buf, size_t len, bool) override {
// This is an error
if (len != chunk_sz)
return false;
@@ -565,7 +562,7 @@ public:
}
protected:
bool write_chunk(const void *buf, size_t len, bool final) override {
bool write_chunk(const void *buf, size_t len, bool) override {
auto in = static_cast<const char *>(buf);
uint32_t block_sz = LZ4_compress_HC(in, out_buf, len, LZ4_COMPRESSED, LZ4HC_CLEVEL_MAX);
if (block_sz == 0) {
@@ -585,7 +582,7 @@ private:
uint32_t in_total;
};
filter_strm_ptr get_encoder(format_t type, out_strm_ptr &&base) {
out_strm_ptr get_encoder(format_t type, out_strm_ptr &&base) {
switch (type) {
case XZ:
return make_unique<xz_encoder>(std::move(base));
@@ -607,7 +604,7 @@ filter_strm_ptr get_encoder(format_t type, out_strm_ptr &&base) {
}
}
filter_strm_ptr get_decoder(format_t type, out_strm_ptr &&base) {
out_strm_ptr get_decoder(format_t type, out_strm_ptr &&base) {
switch (type) {
case XZ:
case LZMA:
@@ -721,7 +718,6 @@ void compress(const char *method, const char *infile, const char *outfile) {
unlink(infile);
}
namespace rust {
bool decompress(const unsigned char *in, uint64_t in_size, int fd) {
format_t type = check_fmt(in, in_size);
@@ -736,4 +732,3 @@ bool decompress(const unsigned char *in, uint64_t in_size, int fd) {
}
return true;
}
}

View File

@@ -4,14 +4,8 @@
#include "format.hpp"
filter_strm_ptr get_encoder(format_t type, out_strm_ptr &&base);
filter_strm_ptr get_decoder(format_t type, out_strm_ptr &&base);
out_strm_ptr get_encoder(format_t type, out_strm_ptr &&base);
out_strm_ptr get_decoder(format_t type, out_strm_ptr &&base);
void compress(const char *method, const char *infile, const char *outfile);
void decompress(char *infile, const char *outfile);
namespace rust {
bool decompress(const unsigned char *in, uint64_t in_size, int fd);
}

View File

@@ -6,13 +6,14 @@ pub use payload::*;
mod payload;
mod update_metadata;
#[cxx::bridge(namespace = "rust")]
#[cxx::bridge]
pub mod ffi {
extern "C++" {
include!("compress.hpp");
pub unsafe fn decompress(in_: *const u8, in_size: u64, fd: i32) -> bool;
}
#[namespace = "rust"]
extern "Rust" {
unsafe fn extract_boot_from_payload(
in_path: *const c_char,