id stringlengths 22 133 | text stringlengths 40 40.2k | arch stringclasses 1
value | syntax stringclasses 1
value | kind stringclasses 4
values | repo stringclasses 27
values | path stringlengths 5 116 | license stringclasses 6
values | commit stringlengths 40 40 | source_host stringclasses 1
value | category stringclasses 16
values | source_url stringlengths 85 196 | line_start int64 1 4.28k | line_end int64 4 4.31k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:10 | assert_eq!(
ByteStream::new(body1).collect().await.unwrap().remaining() as u64,
file_length - some_data.len() as u64
);
}
#[tokio::test]
async fn fsbuilder_length_is_used_as_size_hint() {
let mut file = NamedTempFile::new().unwrap();
write!(
file,... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | e8d176af15ee802809978ce7ec2e2cd4764a3584 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/e8d176af15ee802809978ce7ec2e2cd4764a3584/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 361 | 420 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:11 | .build()
.await
.unwrap()
.into_inner();
assert!(!body.is_end_stream());
assert_eq!(body.content_length(), Some(sentence.len() as u64));
let data = body.data().await.unwrap().unwrap();
assert_eq!(data.len(), sentence.len());
assert!(body.is_e... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | e8d176af15ee802809978ce7ec2e2cd4764a3584 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/e8d176af15ee802809978ce7ec2e2cd4764a3584/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 401 | 460 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:12 | async fn fsbuilder_length_exact() {
let mut file = NamedTempFile::new().unwrap();
let test_sentence = "This sentence is 30 bytes long";
assert_eq!(test_sentence.len(), 30);
write!(file, "{}", test_sentence).unwrap();
// Ensure that the file was written to
file.flush().ex... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | e8d176af15ee802809978ce7ec2e2cd4764a3584 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/e8d176af15ee802809978ce7ec2e2cd4764a3584/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 441 | 500 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:13 | write!(file, "{}", line_0).unwrap();
write!(file, "{}", line_1).unwrap();
// Ensure that the file was written to
file.flush().expect("flushing is OK");
let body = FsBuilder::new()
.path(&file)
// We're going to skip the first line by using offset
.of... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | e8d176af15ee802809978ce7ec2e2cd4764a3584 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/e8d176af15ee802809978ce7ec2e2cd4764a3584/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 481 | 540 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:14 | .build()
.await
.unwrap();
let data = body.collect().await.unwrap().into_bytes();
let data_str = String::from_utf8(data.to_vec()).unwrap();
assert_eq!(&data_str, line_1);
}
#[tokio::test]
async fn fsbuilder_with_offset_greater_than_file_length_returns_error... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | e8d176af15ee802809978ce7ec2e2cd4764a3584 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/e8d176af15ee802809978ce7ec2e2cd4764a3584/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 521 | 580 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:15 | let line_1 = "Line 1\n";
write!(file, "{}", line_0).unwrap();
write!(file, "{}", line_1).unwrap();
// Ensure that the file was written to
file.flush().expect("flushing is OK");
let body = FsBuilder::new()
.path(&file)
.length(Length::UpTo(9000))
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | e8d176af15ee802809978ce7ec2e2cd4764a3584 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/e8d176af15ee802809978ce7ec2e2cd4764a3584/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 561 | 620 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:16 | }
let file_size = file.as_file().metadata().unwrap().len();
// Check that our in-memory copy has the same size as the file
assert_eq!(file_size, in_memory_copy_of_file_contents.len() as u64);
let file_path = file.path().to_path_buf();
let chunks = 7;
let chunk_size = fil... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | e8d176af15ee802809978ce7ec2e2cd4764a3584 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/e8d176af15ee802809978ce7ec2e2cd4764a3584/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 601 | 644 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
use crate::body::SdkBody;
use crate::byte_stream::{error::Error, error::ErrorKind, ByteStream};
use std::future::Future;
use std::path::PathBuf;
use std::pin::Pin;
use tokio::fs::File;
use tokio::io::{se... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | a0ddad15fca029a888f717b770fda078541546c4 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/a0ddad15fca029a888f717b770fda078541546c4/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:2 | offset,
}
}
fn from_file(file: File, length: u64, buffer_size: usize) -> Self {
PathBody {
state: State::Loaded(ReaderStream::with_capacity(file.take(length), buffer_size)),
length,
buffer_size,
// The file used to create this `PathBody` should ha... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | a0ddad15fca029a888f717b770fda078541546c4 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/a0ddad15fca029a888f717b770fda078541546c4/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 41 | 100 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:3 | #[allow(missing_debug_implementations)]
pub struct FsBuilder {
file: Option<File>,
path: Option<PathBuf>,
length: Option<Length>,
buffer_size: usize,
offset: Option<u64>,
}
impl Default for FsBuilder {
fn default() -> Self {
Self::new()
}
}
/// The length (in bytes) to read. Determ... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | a0ddad15fca029a888f717b770fda078541546c4 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/a0ddad15fca029a888f717b770fda078541546c4/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 81 | 140 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:4 | ///
/// NOTE: The resulting ByteStream (after calling [build](FsBuilder::build)) will be retryable.
/// The returned ByteStream will provide a size hint when used as an HTTP body.
/// If the request fails, the read will begin again by reloading the file handle.
pub fn path(mut self, path: impl AsRef<std... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | a0ddad15fca029a888f717b770fda078541546c4 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/a0ddad15fca029a888f717b770fda078541546c4/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 121 | 180 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:5 | pub fn offset(mut self, offset: u64) -> Self {
self.offset = Some(offset);
self
}
/// Returns a [`ByteStream`] from this builder.
pub async fn build(self) -> Result<ByteStream, Error> {
if self.path.is_some() && self.file.is_some() {
panic!("The 'file' and 'path' options... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | a0ddad15fca029a888f717b770fda078541546c4 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/a0ddad15fca029a888f717b770fda078541546c4/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 161 | 220 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:6 | ))
};
Ok(ByteStream::new(SdkBody::retryable(body_loader)))
} else if let Some(mut file) = self.file {
// When starting from a `File`, we need to do our own seeking
if offset != 0 {
let _s = file.seek(io::SeekFrom::Start(offset)).await?;
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | a0ddad15fca029a888f717b770fda078541546c4 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/a0ddad15fca029a888f717b770fda078541546c4/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 201 | 260 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:7 | mut self: std::pin::Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Option<Result<Self::Data, Self::Error>>> {
use std::task::Poll;
let offset = self.offset.unwrap_or(DEFAULT_OFFSET);
loop {
match self.state {
State::Unloaded(ref path... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | a0ddad15fca029a888f717b770fda078541546c4 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/a0ddad15fca029a888f717b770fda078541546c4/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 241 | 300 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:8 | }
fn poll_trailers(
self: std::pin::Pin<&mut Self>,
_cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Result<Option<http::HeaderMap>, Self::Error>> {
std::task::Poll::Ready(Ok(None))
}
fn is_end_stream(&self) -> bool {
// fast path end-stream for empty streams
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | a0ddad15fca029a888f717b770fda078541546c4 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/a0ddad15fca029a888f717b770fda078541546c4/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 281 | 340 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:9 | let body = FsBuilder::new()
.path(&file)
.buffer_size(16384)
.length(Length::Exact(file_length))
.build()
.await
.unwrap()
.into_inner();
// assert that the specified length is used as size hint
assert_eq!(body.content_... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | a0ddad15fca029a888f717b770fda078541546c4 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/a0ddad15fca029a888f717b770fda078541546c4/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 321 | 380 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:10 | let body = FsBuilder::new()
.path(&file)
// The file is longer than 1 byte, let's see if this is used to generate the size hint
.length(Length::Exact(1))
.build()
.await
.unwrap()
.into_inner();
assert_eq!(body.content_length()... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | a0ddad15fca029a888f717b770fda078541546c4 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/a0ddad15fca029a888f717b770fda078541546c4/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 361 | 420 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:11 | let mut file = NamedTempFile::new().unwrap();
let test_sentence = "This sentence is 30 bytes long";
assert_eq!(test_sentence.len(), 30);
write!(file, "{}", test_sentence).unwrap();
// Ensure that the file was written to
file.flush().expect("flushing is OK");
assert!(FsB... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | a0ddad15fca029a888f717b770fda078541546c4 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/a0ddad15fca029a888f717b770fda078541546c4/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 401 | 460 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:12 | write!(file, "{}", line_1).unwrap();
// Ensure that the file was written to
file.flush().expect("flushing is OK");
let body = FsBuilder::new()
.path(&file)
// We're going to skip the first line by using offset
.offset(line_0.len() as u64)
.build(... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | a0ddad15fca029a888f717b770fda078541546c4 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/a0ddad15fca029a888f717b770fda078541546c4/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 441 | 500 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:13 | .await
.unwrap();
let data = body.collect().await.unwrap().into_bytes();
let data_str = String::from_utf8(data.to_vec()).unwrap();
assert_eq!(&data_str, line_1);
}
#[tokio::test]
async fn fsbuilder_with_offset_greater_than_file_length_returns_error() {
let mut ... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | a0ddad15fca029a888f717b770fda078541546c4 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/a0ddad15fca029a888f717b770fda078541546c4/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 481 | 540 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:14 | write!(file, "{}", line_0).unwrap();
write!(file, "{}", line_1).unwrap();
// Ensure that the file was written to
file.flush().expect("flushing is OK");
let body = FsBuilder::new()
.path(&file)
.length(Length::UpTo(9000))
.build()
.await
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | a0ddad15fca029a888f717b770fda078541546c4 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/a0ddad15fca029a888f717b770fda078541546c4/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 521 | 580 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:15 | let file_size = file.as_file().metadata().unwrap().len();
// Check that our in-memory copy has the same size as the file
assert_eq!(file_size, in_memory_copy_of_file_contents.len() as u64);
let file_path = file.path().to_path_buf();
let chunks = 7;
let chunk_size = file_size / ch... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | a0ddad15fca029a888f717b770fda078541546c4 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/a0ddad15fca029a888f717b770fda078541546c4/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 561 | 603 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
use crate::body::SdkBody;
use crate::byte_stream::{error::Error, error::ErrorKind, ByteStream};
use std::future::Future;
use std::path::PathBuf;
use std::pin::Pin;
use tokio::fs::File;
use tokio::io::{se... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | 0ff4059b2486642feaa9d8354e64cac48ff02e56 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/0ff4059b2486642feaa9d8354e64cac48ff02e56/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:2 | offset,
}
}
fn from_file(file: File, length: u64, buffer_size: usize) -> Self {
PathBody {
state: State::Loaded(ReaderStream::with_capacity(file.take(length), buffer_size)),
length,
buffer_size,
/// The file used to create this `PathBody` should h... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | 0ff4059b2486642feaa9d8354e64cac48ff02e56 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/0ff4059b2486642feaa9d8354e64cac48ff02e56/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 41 | 100 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:4 | ///
/// NOTE: The resulting ByteStream (after calling [build](FsBuilder::build)) will be retryable.
/// The returned ByteStream will provide a size hint when used as an HTTP body.
/// If the request fails, the read will begin again by reloading the file handle.
pub fn path(mut self, path: impl AsRef<std... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | 0ff4059b2486642feaa9d8354e64cac48ff02e56 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/0ff4059b2486642feaa9d8354e64cac48ff02e56/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 121 | 180 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:5 | pub fn offset(mut self, offset: u64) -> Self {
self.offset = Some(offset);
self
}
/// Returns a [`ByteStream`](ByteStream) from this builder.
pub async fn build(self) -> Result<ByteStream, Error> {
if self.path.is_some() && self.file.is_some() {
panic!("The 'file' and 'p... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | 0ff4059b2486642feaa9d8354e64cac48ff02e56 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/0ff4059b2486642feaa9d8354e64cac48ff02e56/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 161 | 220 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:6 | ))
};
Ok(ByteStream::new(SdkBody::retryable(body_loader)))
} else if let Some(mut file) = self.file {
// When starting from a `File`, we need to do our own seeking
if offset != 0 {
let _s = file.seek(io::SeekFrom::Start(offset)).await?;
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | 0ff4059b2486642feaa9d8354e64cac48ff02e56 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/0ff4059b2486642feaa9d8354e64cac48ff02e56/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 201 | 260 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:7 | cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Option<Result<Self::Data, Self::Error>>> {
use std::task::Poll;
let offset = self.offset.unwrap_or(DEFAULT_OFFSET);
loop {
match self.state {
State::Unloaded(ref path_buf) => {
let buf = pat... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | 0ff4059b2486642feaa9d8354e64cac48ff02e56 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/0ff4059b2486642feaa9d8354e64cac48ff02e56/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 241 | 300 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:8 | fn poll_trailers(
self: std::pin::Pin<&mut Self>,
_cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Result<Option<http::HeaderMap>, Self::Error>> {
std::task::Poll::Ready(Ok(None))
}
fn is_end_stream(&self) -> bool {
// fast path end-stream for empty streams
sel... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | 0ff4059b2486642feaa9d8354e64cac48ff02e56 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/0ff4059b2486642feaa9d8354e64cac48ff02e56/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 281 | 340 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:10 | .path(&file)
// The file is longer than 1 byte, let's see if this is used to generate the size hint
.length(Length::Exact(1))
.build()
.await
.unwrap()
.into_inner();
assert_eq!(body.content_length(), Some(1));
}
#[tokio::test]
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | 0ff4059b2486642feaa9d8354e64cac48ff02e56 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/0ff4059b2486642feaa9d8354e64cac48ff02e56/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 361 | 420 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:11 | let test_sentence = "This sentence is 30 bytes long";
assert_eq!(test_sentence.len(), 30);
write!(file, "{}", test_sentence).unwrap();
// Ensure that the file was written to
file.flush().expect("flushing is OK");
assert!(FsBuilder::new()
.path(&file)
// ... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | 0ff4059b2486642feaa9d8354e64cac48ff02e56 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/0ff4059b2486642feaa9d8354e64cac48ff02e56/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 401 | 460 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:12 | // Ensure that the file was written to
file.flush().expect("flushing is OK");
let body = FsBuilder::new()
.path(&file)
// We're going to skip the first line by using offset
.offset(line_0.len() as u64)
.build()
.await
.unwrap();
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | 0ff4059b2486642feaa9d8354e64cac48ff02e56 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/0ff4059b2486642feaa9d8354e64cac48ff02e56/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 441 | 500 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:13 | .unwrap();
let data = body.collect().await.unwrap().into_bytes();
let data_str = String::from_utf8(data.to_vec()).unwrap();
assert_eq!(&data_str, line_1);
}
#[tokio::test]
async fn fsbuilder_with_offset_greater_than_file_length_returns_error() {
let mut file = NamedTempFil... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | 0ff4059b2486642feaa9d8354e64cac48ff02e56 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/0ff4059b2486642feaa9d8354e64cac48ff02e56/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 481 | 540 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:14 | write!(file, "{}", line_0).unwrap();
write!(file, "{}", line_1).unwrap();
// Ensure that the file was written to
file.flush().expect("flushing is OK");
let body = FsBuilder::new()
.path(&file)
.length(Length::UpTo(9000))
.build()
.await
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | 0ff4059b2486642feaa9d8354e64cac48ff02e56 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/0ff4059b2486642feaa9d8354e64cac48ff02e56/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 521 | 580 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
use crate::body::SdkBody;
use crate::byte_stream::{error::Error, error::ErrorKind, ByteStream};
use std::future::Future;
use std::path::PathBuf;
use std::pin::Pin;
use std::sync::Arc;
use tokio::fs::File... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | c84a2ea7fe86af81214e389b24844b0be5474808 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/c84a2ea7fe86af81214e389b24844b0be5474808/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:2 | buffer_size,
offset,
}
}
fn from_file(file: File, length: u64, buffer_size: usize) -> Self {
PathBody {
state: State::Loaded(ReaderStream::with_capacity(file.take(length), buffer_size)),
length,
buffer_size,
/// The file used to create... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | c84a2ea7fe86af81214e389b24844b0be5474808 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/c84a2ea7fe86af81214e389b24844b0be5474808/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 41 | 100 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:3 | /// GetObjectInput { body: bytestream }
/// }
/// # }
/// ```
#[allow(missing_debug_implementations)]
pub struct FsBuilder {
file: Option<File>,
path: Option<PathBuf>,
length: Option<Length>,
buffer_size: usize,
offset: Option<u64>,
sdk_body_creator: SdkBodyCreator,
}
enum SdkBodyCreator {
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | c84a2ea7fe86af81214e389b24844b0be5474808 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/c84a2ea7fe86af81214e389b24844b0be5474808/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 81 | 140 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:4 | length: None,
offset: None,
path: None,
sdk_body_creator: SdkBodyCreator::HttpBody04(Arc::new(|body: PathBody| {
SdkBody::from_body_0_4(body)
})),
}
}
/// Sets the path to read from.
///
/// NOTE: The resulting ByteStream (after ca... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | c84a2ea7fe86af81214e389b24844b0be5474808 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/c84a2ea7fe86af81214e389b24844b0be5474808/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 121 | 180 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:5 | /// Increasing the read buffer capacity to higher values than the default (4096 bytes) can result in a large reduction
/// in CPU usage, at the cost of memory increase.
pub fn buffer_size(mut self, buffer_size: usize) -> Self {
self.buffer_size = buffer_size;
self
}
/// Specify the offs... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | c84a2ea7fe86af81214e389b24844b0be5474808 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/c84a2ea7fe86af81214e389b24844b0be5474808/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 161 | 220 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:6 | if let Some(path) = self.path {
let body_loader = move || {
// If an offset was provided, seeking will be handled in `PathBody::poll_data` each
// time the file is loaded.
match &self.sdk_body_creator {
#[cfg(feature = "http-body-0-4-x")]
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | c84a2ea7fe86af81214e389b24844b0be5474808 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/c84a2ea7fe86af81214e389b24844b0be5474808/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 201 | 260 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:7 | }
async fn get_file_size(&self) -> Result<u64, Error> {
Ok(match self.path.as_ref() {
Some(path) => tokio::fs::metadata(path).await,
// If it's not path-based then it's file-based
None => self.file.as_ref().unwrap().metadata().await,
}
.map(|metadata| met... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | c84a2ea7fe86af81214e389b24844b0be5474808 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/c84a2ea7fe86af81214e389b24844b0be5474808/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 241 | 300 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:8 | Ok(file)
}));
}
State::Loading(ref mut future) => {
match futures_core::ready!(Pin::new(future).poll(cx)) {
Ok(file) => {
self.state = State::Loaded(ReaderStream::with_capacity(
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | c84a2ea7fe86af81214e389b24844b0be5474808 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/c84a2ea7fe86af81214e389b24844b0be5474808/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 281 | 340 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:9 | }
}
#[cfg(feature = "http-body-0-4-x")]
#[cfg(test)]
mod test {
use super::FsBuilder;
use crate::byte_stream::{ByteStream, Length};
use bytes::Buf;
use std::io::Write;
use tempfile::NamedTempFile;
#[tokio::test]
async fn path_based_bytestreams_with_builder() {
let mut file = NamedT... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | c84a2ea7fe86af81214e389b24844b0be5474808 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/c84a2ea7fe86af81214e389b24844b0be5474808/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 321 | 380 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:10 | .next()
.await
.expect("should have some data")
.expect("read should not fail");
// The size of one read should be equal to that of the buffer size
assert_eq!(some_data.len(), 16384);
assert_eq!(
ByteStream::new(body1).collect().await.unwrap().rem... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | c84a2ea7fe86af81214e389b24844b0be5474808 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/c84a2ea7fe86af81214e389b24844b0be5474808/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 361 | 420 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:11 | let line_1 = "Line 1\n";
write!(file, "{}", line_0).unwrap();
write!(file, "{}", line_1).unwrap();
// Ensure that the file was written to
file.flush().expect("flushing is OK");
let body = FsBuilder::new_with_body_0_4()
.path(&file)
// We're going to rea... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | c84a2ea7fe86af81214e389b24844b0be5474808 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/c84a2ea7fe86af81214e389b24844b0be5474808/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 401 | 460 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:12 | assert!(FsBuilder::new_with_body_0_4()
.path(&file)
// The file is 30 bytes so this is fine
.length(Length::Exact(30))
.build()
.await
.is_ok());
assert!(FsBuilder::new_with_body_0_4()
.path(&file)
// Larger than 30... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | c84a2ea7fe86af81214e389b24844b0be5474808 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/c84a2ea7fe86af81214e389b24844b0be5474808/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 441 | 500 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:13 | assert_eq!(&data_str, line_1);
}
#[tokio::test]
async fn fsbuilder_offset_and_length_work_together() {
let mut file = NamedTempFile::new().unwrap();
let line_0 = "Line 0\n";
let line_1 = "Line 1\n";
let line_2 = "Line 2\n";
write!(file, "{}", line_0).unwrap();
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | c84a2ea7fe86af81214e389b24844b0be5474808 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/c84a2ea7fe86af81214e389b24844b0be5474808/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 481 | 540 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:14 | write!(file, "{}", line_1).unwrap();
// Ensure that the file was written to
file.flush().expect("flushing is OK");
assert_eq!(
FsBuilder::new_with_body_0_4()
.path(&file)
// We're going to skip all file contents by setting an offset
/... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | c84a2ea7fe86af81214e389b24844b0be5474808 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/c84a2ea7fe86af81214e389b24844b0be5474808/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 521 | 580 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:15 | assert_eq!(data_str, format!("{}{}", line_0, line_1));
}
#[tokio::test]
async fn fsbuilder_can_be_used_for_chunking() {
let mut file = NamedTempFile::new().unwrap();
let mut in_memory_copy_of_file_contents = String::new();
// I put these two write loops in separate blocks so that th... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | c84a2ea7fe86af81214e389b24844b0be5474808 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/c84a2ea7fe86af81214e389b24844b0be5474808/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 561 | 620 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs:16 | chunk_size
};
let byte_stream = FsBuilder::new_with_body_0_4()
.path(&file_path)
.offset(i * chunk_size)
.length(Length::Exact(length))
.build()
.await
.unwrap();
byte_streams.push(byte_... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | Apache-2.0 | c84a2ea7fe86af81214e389b24844b0be5474808 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/c84a2ea7fe86af81214e389b24844b0be5474808/sdk/aws-smithy-types/src/byte_stream/bytestream_util.rs | 601 | 627 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
use super::{PathBody, State, DEFAULT_OFFSET};
use std::future::Future;
use std::pin::Pin;
use std::task::Poll;
use tokio::fs::File;
use tokio::io;
use tokio::io::{AsyncReadExt, AsyncSeekExt};
use tokio_u... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs:2 | self.state = State::Loaded {
stream: ReaderStream::with_capacity(
file.take(self.length),
self.buffer_size,
),
bytes_left: self.length,
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | 41 | 100 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs:3 | }
}
fn size_hint(&self) -> http_body_0_4::SizeHint {
http_body_0_4::SizeHint::with_exact(self.length)
}
}
#[cfg(test)]
mod test {
use crate::byte_stream::{ByteStream, FsBuilder, Length};
use bytes::Buf;
use http_body_0_4::Body;
use std::io::Write;
use tempfile::NamedTempFile;
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | 81 | 140 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs:4 | let mut body = body.try_clone().expect("retryable bodies are cloneable");
// read a little bit from one of the clones
let some_data = body
.next()
.await
.expect("should have some data")
.expect("read should not fail");
// The size of one read shou... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | 121 | 180 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs:5 | #[tokio::test]
async fn fsbuilder_is_end_stream() {
let sentence = "A very long sentence that's clearly longer than a single byte.";
let mut file = NamedTempFile::new().unwrap();
file.write_all(sentence.as_bytes()).unwrap();
// Ensure that the file was written to
file.flush()... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | 161 | 220 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs:6 | .await
.unwrap();
let data = body.collect().await.unwrap().into_bytes();
let data_str = String::from_utf8(data.to_vec()).unwrap();
assert_eq!(&data_str, line_0);
}
#[tokio::test]
async fn fsbuilder_length_exact() {
let mut file = NamedTempFile::new().unwrap();
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | 201 | 260 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs:7 | .await
.is_err());
}
#[tokio::test]
async fn fsbuilder_supports_offset() {
let mut file = NamedTempFile::new().unwrap();
let line_0 = "Line 0\n";
let line_1 = "Line 1\n";
write!(file, "{line_0}").unwrap();
write!(file, "{line_1}").unwrap();
// E... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | 241 | 300 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs:8 | // Ensure that the file was written to
file.flush().expect("flushing is OK");
let body = FsBuilder::new()
.path(&file)
// We're going to skip line 0 by using offset
.offset(line_0.len() as u64)
// We want to read only line 1 and stop before we get to line... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | 281 | 340 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs:9 | .unwrap_err()
.to_string(),
"offset must be less than or equal to file size but was greater than"
);
}
#[tokio::test]
async fn fsbuilder_with_length_greater_than_file_length_reads_everything() {
let mut file = NamedTempFile::new().unwrap();
let line_0 = "... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | 321 | 380 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs:10 | }
}
{
use std::fmt::Write;
for i in 0..1000 {
writeln!(in_memory_copy_of_file_contents, "Line {i:04}").unwrap();
}
// Check we wrote the lines
assert!(!in_memory_copy_of_file_contents.is_empty());
}
let file_si... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | 361 | 414 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs:11 | let mut collected_bytes = Vec::new();
for byte_stream in byte_streams.into_iter() {
let bytes = byte_stream.collect().await.unwrap().into_bytes();
collected_bytes.push(bytes);
}
let bytes = collected_bytes.concat();
let data_str = String::from_utf8(bytes.to_vec(... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | 401 | 414 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs:3 | }
}
fn size_hint(&self) -> http_body_0_4::SizeHint {
http_body_0_4::SizeHint::with_exact(self.length)
}
}
#[cfg(test)]
mod test {
use crate::byte_stream::{ByteStream, FsBuilder, Length};
use bytes::Buf;
use http_body_0_4::Body;
use std::io::Write;
use tempfile::NamedTempFile;
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | Apache-2.0 | 7e06e1dbb2d1cb7a208360dd934633dc4affe6f2 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7e06e1dbb2d1cb7a208360dd934633dc4affe6f2/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | 81 | 140 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs:5 | #[tokio::test]
async fn fsbuilder_is_end_stream() {
let sentence = "A very long sentence that's clearly longer than a single byte.";
let mut file = NamedTempFile::new().unwrap();
file.write_all(sentence.as_bytes()).unwrap();
// Ensure that the file was written to
file.flush()... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | Apache-2.0 | 7e06e1dbb2d1cb7a208360dd934633dc4affe6f2 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7e06e1dbb2d1cb7a208360dd934633dc4affe6f2/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | 161 | 220 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs:6 | .await
.unwrap();
let data = body.collect().await.unwrap().into_bytes();
let data_str = String::from_utf8(data.to_vec()).unwrap();
assert_eq!(&data_str, line_0);
}
#[tokio::test]
async fn fsbuilder_length_exact() {
let mut file = NamedTempFile::new().unwrap();
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | Apache-2.0 | 7e06e1dbb2d1cb7a208360dd934633dc4affe6f2 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7e06e1dbb2d1cb7a208360dd934633dc4affe6f2/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | 201 | 260 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs:7 | .await
.is_err());
}
#[tokio::test]
async fn fsbuilder_supports_offset() {
let mut file = NamedTempFile::new().unwrap();
let line_0 = "Line 0\n";
let line_1 = "Line 1\n";
write!(file, "{}", line_0).unwrap();
write!(file, "{}", line_1).unwrap();
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | Apache-2.0 | 7e06e1dbb2d1cb7a208360dd934633dc4affe6f2 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7e06e1dbb2d1cb7a208360dd934633dc4affe6f2/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | 241 | 300 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs:8 | // Ensure that the file was written to
file.flush().expect("flushing is OK");
let body = FsBuilder::new()
.path(&file)
// We're going to skip line 0 by using offset
.offset(line_0.len() as u64)
// We want to read only line 1 and stop before we get to line... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | Apache-2.0 | 7e06e1dbb2d1cb7a208360dd934633dc4affe6f2 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7e06e1dbb2d1cb7a208360dd934633dc4affe6f2/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | 281 | 340 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs:9 | .unwrap_err()
.to_string(),
"offset must be less than or equal to file size but was greater than"
);
}
#[tokio::test]
async fn fsbuilder_with_length_greater_than_file_length_reads_everything() {
let mut file = NamedTempFile::new().unwrap();
let line_0 = "... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | Apache-2.0 | 7e06e1dbb2d1cb7a208360dd934633dc4affe6f2 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7e06e1dbb2d1cb7a208360dd934633dc4affe6f2/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | 321 | 380 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs:10 | }
}
{
use std::fmt::Write;
for i in 0..1000 {
writeln!(in_memory_copy_of_file_contents, "Line {:04}", i).unwrap();
}
// Check we wrote the lines
assert!(!in_memory_copy_of_file_contents.is_empty());
}
let file_... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | Apache-2.0 | 7e06e1dbb2d1cb7a208360dd934633dc4affe6f2 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7e06e1dbb2d1cb7a208360dd934633dc4affe6f2/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_0_4_x.rs | 361 | 414 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
use super::{PathBody, State, DEFAULT_OFFSET};
use http_body_1_0::{Body, Frame, SizeHint};
use std::future::Future;
use std::pin::Pin;
use std::task::Poll;
use tokio::fs::File;
use tokio::io::{AsyncReadEx... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs:2 | self.state = State::Loaded {
stream: ReaderStream::with_capacity(
file.take(self.length),
self.buffer_size,
),
bytes_left: self.length,
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | 41 | 100 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs:3 | #[cfg(test)]
mod test {
use crate::byte_stream::{ByteStream, FsBuilder, Length};
use bytes::Buf;
use http_body_util::BodyExt;
use std::io::Write;
use tempfile::NamedTempFile;
#[tokio::test]
async fn path_based_bytestreams_with_builder() {
let mut file = NamedTempFile::new().unwrap()... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | 81 | 140 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs:4 | .expect("read should not fail");
// The size of one read should be equal to that of the buffer size
assert_eq!(some_data.len(), 16384);
assert_eq!(
ByteStream::new(body).collect().await.unwrap().remaining() as u64,
file_length - some_data.len() as u64
);
}
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | 121 | 180 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs:5 | let body = FsBuilder::new()
.path(&file)
.build()
.await
.unwrap()
.into_inner();
assert!(!body.is_end_stream());
assert_eq!(body.content_length(), Some(sentence.len() as u64));
let data = BodyExt::collect(body).await.unwrap().to_bytes... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | 161 | 220 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs:6 | #[tokio::test]
async fn fsbuilder_length_exact() {
let mut file = NamedTempFile::new().unwrap();
let test_sentence = "This sentence is 30 bytes long";
assert_eq!(test_sentence.len(), 30);
write!(file, "{test_sentence}").unwrap();
// Ensure that the file was written to
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | 201 | 260 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs:7 | write!(file, "{line_0}").unwrap();
write!(file, "{line_1}").unwrap();
// Ensure that the file was written to
file.flush().expect("flushing is OK");
let body = FsBuilder::new()
.path(&file)
// We're going to skip the first line by using offset
.offset... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | 241 | 300 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs:8 | .length(Length::Exact(line_1.len() as u64))
.build()
.await
.unwrap();
let data = body.collect().await.unwrap().into_bytes();
let data_str = String::from_utf8(data.to_vec()).unwrap();
assert_eq!(&data_str, line_1);
}
#[tokio::test]
async fn fsbu... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | 281 | 340 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs:9 | let line_0 = "Line 0\n";
let line_1 = "Line 1\n";
write!(file, "{line_0}").unwrap();
write!(file, "{line_1}").unwrap();
// Ensure that the file was written to
file.flush().expect("flushing is OK");
let body = FsBuilder::new()
.path(&file)
.lengt... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | 321 | 380 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs:10 | assert!(!in_memory_copy_of_file_contents.is_empty());
}
let file_size = file.as_file().metadata().unwrap().len();
// Check that our in-memory copy has the same size as the file
assert_eq!(file_size, in_memory_copy_of_file_contents.len() as u64);
let file_path = file.path().to_pa... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | 361 | 405 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs:2 | self.state = State::Loaded {
stream: ReaderStream::with_capacity(
file.take(self.length),
self.buffer_size,
),
bytes_left: self.length,
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | Apache-2.0 | 7e06e1dbb2d1cb7a208360dd934633dc4affe6f2 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7e06e1dbb2d1cb7a208360dd934633dc4affe6f2/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | 41 | 100 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs:3 | #[cfg(test)]
mod test {
use crate::byte_stream::{ByteStream, FsBuilder, Length};
use bytes::Buf;
use http_body_util::BodyExt;
use std::io::Write;
use tempfile::NamedTempFile;
#[tokio::test]
async fn path_based_bytestreams_with_builder() {
let mut file = NamedTempFile::new().unwrap()... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | Apache-2.0 | 7e06e1dbb2d1cb7a208360dd934633dc4affe6f2 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7e06e1dbb2d1cb7a208360dd934633dc4affe6f2/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | 81 | 140 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs:5 | let body = FsBuilder::new()
.path(&file)
.build()
.await
.unwrap()
.into_inner();
assert!(!body.is_end_stream());
assert_eq!(body.content_length(), Some(sentence.len() as u64));
let data = BodyExt::collect(body).await.unwrap().to_bytes... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | Apache-2.0 | 7e06e1dbb2d1cb7a208360dd934633dc4affe6f2 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7e06e1dbb2d1cb7a208360dd934633dc4affe6f2/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | 161 | 220 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs:6 | #[tokio::test]
async fn fsbuilder_length_exact() {
let mut file = NamedTempFile::new().unwrap();
let test_sentence = "This sentence is 30 bytes long";
assert_eq!(test_sentence.len(), 30);
write!(file, "{}", test_sentence).unwrap();
// Ensure that the file was written to
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | Apache-2.0 | 7e06e1dbb2d1cb7a208360dd934633dc4affe6f2 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7e06e1dbb2d1cb7a208360dd934633dc4affe6f2/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | 201 | 260 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs:7 | write!(file, "{}", line_0).unwrap();
write!(file, "{}", line_1).unwrap();
// Ensure that the file was written to
file.flush().expect("flushing is OK");
let body = FsBuilder::new()
.path(&file)
// We're going to skip the first line by using offset
.of... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | Apache-2.0 | 7e06e1dbb2d1cb7a208360dd934633dc4affe6f2 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7e06e1dbb2d1cb7a208360dd934633dc4affe6f2/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | 241 | 300 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs:8 | .length(Length::Exact(line_1.len() as u64))
.build()
.await
.unwrap();
let data = body.collect().await.unwrap().into_bytes();
let data_str = String::from_utf8(data.to_vec()).unwrap();
assert_eq!(&data_str, line_1);
}
#[tokio::test]
async fn fsbu... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | Apache-2.0 | 7e06e1dbb2d1cb7a208360dd934633dc4affe6f2 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7e06e1dbb2d1cb7a208360dd934633dc4affe6f2/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | 281 | 340 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs:9 | let line_0 = "Line 0\n";
let line_1 = "Line 1\n";
write!(file, "{}", line_0).unwrap();
write!(file, "{}", line_1).unwrap();
// Ensure that the file was written to
file.flush().expect("flushing is OK");
let body = FsBuilder::new()
.path(&file)
.l... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | Apache-2.0 | 7e06e1dbb2d1cb7a208360dd934633dc4affe6f2 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7e06e1dbb2d1cb7a208360dd934633dc4affe6f2/sdk/aws-smithy-types/src/byte_stream/bytestream_util/http_body_1_x.rs | 321 | 380 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/error.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
//! Errors related to bytestreams.
use std::error::Error as StdError;
use std::fmt;
use std::io::Error as IoError;
#[derive(Debug)]
pub(super) enum ErrorKind {
#[cfg(feature = "rt-tokio")]
Offs... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/error.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/byte_stream/error.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/error.rs:2 | fn from(err: IoError) -> Self {
ErrorKind::IoError(err).into()
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.kind {
#[cfg(feature = "rt-tokio")]
ErrorKind::OffsetLargerThanFileSize => write!(
f,
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/error.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/byte_stream/error.rs | 41 | 81 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
use crate::body::SdkBody;
use crate::byte_stream::ByteStream;
use bytes::Bytes;
impl ByteStream {
/// Construct a `ByteStream` from a type that implements [`http_body_0_4::Body<Data = Bytes>`](http_... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs:2 | tokio::spawn(async move {
sender.send_data(Bytes::from("data 1")).await.unwrap();
sender.send_data(Bytes::from("data 2")).await.unwrap();
sender.send_data(Bytes::from("data 3")).await.unwrap();
});
assert_eq!(
byte_stream.collect().await.expect("no errors"... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs | 41 | 92 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs:3 | assert!(body2.starts_with(b"Brian was here."));
assert!(body2.ends_with(b"9999\n"));
assert_eq!(body2.len(), 298890);
assert_eq!(
ByteStream::new(body1).collect().await?.remaining(),
298890 - some_data.len()
);
Ok(())
}
} | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs | 81 | 92 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs:2 | tokio::spawn(async move {
sender.send_data(Bytes::from("data 1")).await.unwrap();
sender.send_data(Bytes::from("data 2")).await.unwrap();
sender.send_data(Bytes::from("data 3")).await.unwrap();
});
assert_eq!(
byte_stream.collect().await.expect("no errors"... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs | Apache-2.0 | 3b61e78010e79d30cc38661acebacc6ff89ed84a | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/3b61e78010e79d30cc38661acebacc6ff89ed84a/sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs | 41 | 92 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
use crate::body::SdkBody;
use crate::byte_stream::ByteStream;
use bytes::Bytes;
impl ByteStream {
/// Construct a `ByteStream` from a type that implements [`http_body_0_4::Body<Data = Bytes>`](http_... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs | Apache-2.0 | 7e06e1dbb2d1cb7a208360dd934633dc4affe6f2 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7e06e1dbb2d1cb7a208360dd934633dc4affe6f2/sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs:2 | sender.send_data(Bytes::from("data 1")).await.unwrap();
sender.send_data(Bytes::from("data 2")).await.unwrap();
sender.send_data(Bytes::from("data 3")).await.unwrap();
});
assert_eq!(
byte_stream.collect().await.expect("no errors").into_bytes(),
Bytes::fro... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs | Apache-2.0 | 7e06e1dbb2d1cb7a208360dd934633dc4affe6f2 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7e06e1dbb2d1cb7a208360dd934633dc4affe6f2/sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs | 41 | 91 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs:3 | assert!(body2.ends_with(b"9999\n"));
assert_eq!(body2.len(), 298890);
assert_eq!(
ByteStream::new(body1).collect().await?.remaining(),
298890 - some_data.len()
);
Ok(())
}
} | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs | Apache-2.0 | 7e06e1dbb2d1cb7a208360dd934633dc4affe6f2 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7e06e1dbb2d1cb7a208360dd934633dc4affe6f2/sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs | 81 | 91 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
use crate::body::SdkBody;
use crate::byte_stream::ByteStream;
use bytes::Bytes;
impl ByteStream {
/// Construct a `ByteStream` from a type that implements [`http_body_0_4::Body<Data = Bytes>`](http_... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs | Apache-2.0 | 0ff4059b2486642feaa9d8354e64cac48ff02e56 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/0ff4059b2486642feaa9d8354e64cac48ff02e56/sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
use crate::body::SdkBody;
use crate::byte_stream::ByteStream;
use bytes::Bytes;
impl ByteStream {
/// Construct a `ByteStream` from a type that implements [`http_body_0_4::Body<Data = Bytes>`](http_... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs | Apache-2.0 | c84a2ea7fe86af81214e389b24844b0be5474808 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/c84a2ea7fe86af81214e389b24844b0be5474808/sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs:2 | /// # }
/// ```
#[cfg(feature = "rt-tokio")]
#[cfg_attr(docsrs, doc(cfg(feature = "rt-tokio")))]
pub fn read_with_body_0_4_from() -> crate::byte_stream::FsBuilder {
crate::byte_stream::FsBuilder::new_with_body_0_4()
}
/// Create a ByteStream that streams data from the filesystem
///... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs | Apache-2.0 | c84a2ea7fe86af81214e389b24844b0be5474808 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/c84a2ea7fe86af81214e389b24844b0be5474808/sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs | 41 | 100 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs:3 | .await
}
/// Create a ByteStream from a file
///
/// NOTE: This will NOT result in a retryable ByteStream. For a ByteStream that can be retried in the case of
/// upstream failures, use [`ByteStream::from_path_body_0_4`](ByteStream::from_path_body_0_4)
#[deprecated(
since = "0.40.0",
... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs | Apache-2.0 | c84a2ea7fe86af81214e389b24844b0be5474808 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/c84a2ea7fe86af81214e389b24844b0be5474808/sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs | 81 | 140 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs:4 | tokio::spawn(async move {
sender.send_data(Bytes::from("data 1")).await.unwrap();
sender.send_data(Bytes::from("data 2")).await.unwrap();
sender.send_data(Bytes::from("data 3")).await.unwrap();
});
assert_eq!(
byte_stream.collect().await.expect("no errors"... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs | Apache-2.0 | c84a2ea7fe86af81214e389b24844b0be5474808 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/c84a2ea7fe86af81214e389b24844b0be5474808/sdk/aws-smithy-types/src/byte_stream/http_body_0_4_x.rs | 121 | 172 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/byte_stream/http_body_1_x.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
//! Adapters to use http-body 1.0 bodies with SdkBody & ByteStream
use crate::body::SdkBody;
use crate::byte_stream::ByteStream;
use bytes::Bytes;
impl ByteStream {
/// Construct a `ByteStream` fro... | rust | rust | rust-source | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/byte_stream/http_body_1_x.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/byte_stream/http_body_1_x.rs | 1 | 23 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.