Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gzip fix #56

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions snowflake-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ polars-io = { version = ">=0.32", features = [
glob = { version = "0.3" }
object_store = { version = "0.11", features = ["aws"] }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
flate2 = "1.0.34"

[dev-dependencies]
anyhow = "1"
Expand Down
25 changes: 22 additions & 3 deletions snowflake-api/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ use thiserror::Error;
use url::Url;
use uuid::Uuid;

use std::io::Read;
use flate2::bufread::GzDecoder;
use bytes;

#[derive(Error, Debug)]
pub enum ConnectionError {
#[error(transparent)]
Expand Down Expand Up @@ -183,7 +187,7 @@ impl Connection {
for (k, v) in headers {
header_map.insert(
HeaderName::from_bytes(k.as_bytes()).unwrap(),
HeaderValue::from_bytes(v.as_bytes()).unwrap(),
HeaderValue::from_bytes(v.as_bytes())?,
);
}
let bytes = self
Expand All @@ -193,7 +197,22 @@ impl Connection {
.send()
.await?
.bytes()
.await?;
Ok(bytes)
.await;

match bytes {
Ok(bytes) => {
// convert from gzip to Bytes
let mut gz = GzDecoder::new(&bytes[..]);
let mut decoded_bytes = Vec::new();
gz.read_to_end(&mut decoded_bytes).expect("Failed to decode bytes");
let decoded = bytes::Bytes::copy_from_slice(&decoded_bytes);

Ok(decoded)
}
Err(e) => {
Err(ConnectionError::RequestError(e))
}
}

}
}