Skip to main content

ByteStream

Struct ByteStream 

Source
pub struct ByteStream { /* private fields */ }
Expand description

Wraps an AAByteStream handle.

Implementations§

Source§

impl ByteStream

Source

pub fn from_fd(fd: RawFd, automatic_close: bool) -> Result<Self>

Wraps AAFileStreamOpenWithFD.

Source

pub fn from_file(file: File) -> Result<Self>

Wraps AAFileStreamOpenWithFD through File ownership.

Source

pub fn open_with_path( path: &str, open_flags: i32, open_mode: u32, ) -> Result<Self>

Wraps AAFileStreamOpenWithPath.

Examples found in repository?
examples/05_aa_byte_stream_pipeline.rs (line 18)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11    let input = pseudo_random_bytes(32 * 1024);
12    let artifact_dir = artifact_dir("aa-byte-stream");
13    let plain_path = artifact_dir.join("payload.bin");
14    let compressed_path = artifact_dir.join("payload.pbzx");
15    fs::write(&plain_path, &input)?;
16
17    let mut input_stream =
18        ByteStream::open_with_path(&path_string(&plain_path), OPEN_READ_ONLY, 0)?;
19    let compressed_stream = ByteStream::open_with_path(
20        &path_string(&compressed_path),
21        OPEN_WRITE_ONLY | OPEN_CREATE | OPEN_TRUNCATE,
22        DEFAULT_FILE_MODE,
23    )?;
24    let mut compressed_stream = compressed_stream.into_compression_output(
25        ArchiveCompressionAlgorithm::Lzfse,
26        64 * 1024,
27        ArchiveFlags::empty(),
28        0,
29    )?;
30    input_stream.process_into(&mut compressed_stream)?;
31    compressed_stream.close()?;
32
33    let compressed_stream =
34        ByteStream::open_with_path(&path_string(&compressed_path), OPEN_READ_ONLY, 0)?;
35    let mut decompressed_stream =
36        compressed_stream.into_decompression_input(ArchiveFlags::empty(), 0)?;
37    let output = decompressed_stream.read_to_end()?;
38    assert_eq!(output, input);
39    decompressed_stream.close()?;
40
41    let compressed_len = fs::metadata(&compressed_path)?.len();
42    println!("compressed bytes={compressed_len}");
43    println!("✅ AppleArchive byte-stream pipeline OK");
44    Ok(())
45}
More examples
Hide additional examples
examples/10_aea_roundtrip.rs (lines 20-24)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11    let artifact_dir = artifact_dir("aea-roundtrip");
12    let archive_path = path_string(&artifact_dir.join("example.aea"));
13    let payload = pseudo_random_bytes(16 * 1024);
14
15    let mut context = AeaContext::with_profile(AeaProfile::HkdfSha256AesctrHmacSymmetricNone)?;
16    context.set_padding_size(AeaPadding::NONE)?;
17    context.set_compression_algorithm(ArchiveCompressionAlgorithm::Lzfse)?;
18    context.generate_field_blob(AeaContextField::SymmetricKey)?;
19
20    let stream = ByteStream::open_with_path(
21        &archive_path,
22        OPEN_READ_WRITE | OPEN_CREATE | OPEN_TRUNCATE,
23        DEFAULT_FILE_MODE,
24    )?;
25    let mut encrypted = context.encryption_output_stream(stream, ArchiveFlags::empty(), 0)?;
26    encrypted.write_all(&payload)?;
27    context.close_encryption_output_stream(&mut encrypted)?;
28
29    let symmetric_key = context.field_blob(
30        AeaContextField::SymmetricKey,
31        AeaContextFieldRepresentation::Raw,
32    )?;
33    let mut input = ByteStream::open_with_path(&archive_path, OPEN_READ_ONLY, 0)?;
34    let mut decrypt_context = AeaContext::from_encrypted_stream(&mut input)?;
35    decrypt_context.set_symmetric_key(&symmetric_key)?;
36    let mut decrypted = decrypt_context.decryption_input_stream(input, ArchiveFlags::empty(), 0)?;
37    assert_eq!(decrypted.read_to_end()?, payload);
38
39    println!(
40        "raw_size={} container_size={}",
41        context.raw_size()?,
42        context.container_size()?
43    );
44    println!("✅ AppleEncryptedArchive roundtrip OK");
45    Ok(())
46}
examples/04_aa_archive_stream_roundtrip.rs (lines 23-27)
9fn main() -> Result<(), Box<dyn std::error::Error>> {
10    let data = b"hello from apple archive".to_vec();
11    let artifact_dir = artifact_dir("aa-archive-stream");
12    let archive_path = artifact_dir.join("sample.aar");
13    let archive_path = path_string(&archive_path);
14
15    let mut header = Header::new()?;
16    let regular_file = u64::from(b'F');
17    let data_len = u64::try_from(data.len())?;
18    header.append_field_uint(FieldKey::TYP, regular_file)?;
19    header.append_field_string(FieldKey::PAT, "greeting.txt")?;
20    header.append_field_uint(FieldKey::SIZ, data_len)?;
21    header.append_field_blob(FieldKey::DAT, data_len)?;
22
23    let byte_stream = ByteStream::open_with_path(
24        &archive_path,
25        OPEN_WRITE_ONLY | OPEN_CREATE | OPEN_TRUNCATE,
26        DEFAULT_FILE_MODE,
27    )?;
28    let mut archive = ArchiveStream::encode_output(byte_stream, ArchiveFlags::empty(), 0)?;
29    archive.write_header(&header)?;
30    archive.write_blob(FieldKey::DAT, &data)?;
31    archive.close()?;
32
33    let byte_stream = ByteStream::open_with_path(&archive_path, OPEN_READ_ONLY, 0)?;
34    let mut archive = ArchiveStream::decode_input(byte_stream, ArchiveFlags::empty(), 0)?;
35    let header = archive.read_header()?.expect("archive entry");
36    assert_eq!(header.path()?.as_deref(), Some("greeting.txt"));
37    let blob = header.blob_with_key(FieldKey::DAT)?.expect("blob field");
38    let mut decoded = vec![0_u8; usize::try_from(blob.size)?];
39    archive.read_blob(FieldKey::DAT, &mut decoded)?;
40    assert_eq!(decoded, data);
41    assert!(archive.read_header()?.is_none());
42    archive.close()?;
43
44    println!("archive path={archive_path}");
45    println!("✅ AppleArchive round-trip OK");
46    Ok(())
47}
Source

pub fn temp_file() -> Result<Self>

Wraps AATempFileStreamOpen.

Source

pub fn shared_buffer_pipe(buffer_capacity: usize) -> Result<(Self, Self)>

Wraps AASharedBufferPipeOpen.

Source

pub fn into_compression_output( self, compression_algorithm: ArchiveCompressionAlgorithm, block_size: usize, flags: ArchiveFlags, n_threads: i32, ) -> Result<Self>

Wraps AACompressionOutputStreamOpen.

Examples found in repository?
examples/05_aa_byte_stream_pipeline.rs (lines 24-29)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11    let input = pseudo_random_bytes(32 * 1024);
12    let artifact_dir = artifact_dir("aa-byte-stream");
13    let plain_path = artifact_dir.join("payload.bin");
14    let compressed_path = artifact_dir.join("payload.pbzx");
15    fs::write(&plain_path, &input)?;
16
17    let mut input_stream =
18        ByteStream::open_with_path(&path_string(&plain_path), OPEN_READ_ONLY, 0)?;
19    let compressed_stream = ByteStream::open_with_path(
20        &path_string(&compressed_path),
21        OPEN_WRITE_ONLY | OPEN_CREATE | OPEN_TRUNCATE,
22        DEFAULT_FILE_MODE,
23    )?;
24    let mut compressed_stream = compressed_stream.into_compression_output(
25        ArchiveCompressionAlgorithm::Lzfse,
26        64 * 1024,
27        ArchiveFlags::empty(),
28        0,
29    )?;
30    input_stream.process_into(&mut compressed_stream)?;
31    compressed_stream.close()?;
32
33    let compressed_stream =
34        ByteStream::open_with_path(&path_string(&compressed_path), OPEN_READ_ONLY, 0)?;
35    let mut decompressed_stream =
36        compressed_stream.into_decompression_input(ArchiveFlags::empty(), 0)?;
37    let output = decompressed_stream.read_to_end()?;
38    assert_eq!(output, input);
39    decompressed_stream.close()?;
40
41    let compressed_len = fs::metadata(&compressed_path)?.len();
42    println!("compressed bytes={compressed_len}");
43    println!("✅ AppleArchive byte-stream pipeline OK");
44    Ok(())
45}
Source

pub fn into_existing_compression_output( self, flags: ArchiveFlags, n_threads: i32, ) -> Result<Self>

Wraps AACompressionOutputStreamOpenExisting.

Source

pub fn into_decompression_input( self, flags: ArchiveFlags, n_threads: i32, ) -> Result<Self>

Wraps AADecompressionInputStreamOpen.

Examples found in repository?
examples/05_aa_byte_stream_pipeline.rs (line 36)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11    let input = pseudo_random_bytes(32 * 1024);
12    let artifact_dir = artifact_dir("aa-byte-stream");
13    let plain_path = artifact_dir.join("payload.bin");
14    let compressed_path = artifact_dir.join("payload.pbzx");
15    fs::write(&plain_path, &input)?;
16
17    let mut input_stream =
18        ByteStream::open_with_path(&path_string(&plain_path), OPEN_READ_ONLY, 0)?;
19    let compressed_stream = ByteStream::open_with_path(
20        &path_string(&compressed_path),
21        OPEN_WRITE_ONLY | OPEN_CREATE | OPEN_TRUNCATE,
22        DEFAULT_FILE_MODE,
23    )?;
24    let mut compressed_stream = compressed_stream.into_compression_output(
25        ArchiveCompressionAlgorithm::Lzfse,
26        64 * 1024,
27        ArchiveFlags::empty(),
28        0,
29    )?;
30    input_stream.process_into(&mut compressed_stream)?;
31    compressed_stream.close()?;
32
33    let compressed_stream =
34        ByteStream::open_with_path(&path_string(&compressed_path), OPEN_READ_ONLY, 0)?;
35    let mut decompressed_stream =
36        compressed_stream.into_decompression_input(ArchiveFlags::empty(), 0)?;
37    let output = decompressed_stream.read_to_end()?;
38    assert_eq!(output, input);
39    decompressed_stream.close()?;
40
41    let compressed_len = fs::metadata(&compressed_path)?.len();
42    println!("compressed bytes={compressed_len}");
43    println!("✅ AppleArchive byte-stream pipeline OK");
44    Ok(())
45}
Source

pub fn into_random_access_decompression_input( self, alloc_limit: usize, flags: ArchiveFlags, n_threads: i32, ) -> Result<Self>

Wraps AADecompressionRandomAccessInputStreamOpen.

Source

pub fn write(&mut self, buffer: &[u8]) -> Result<usize>

Wraps AAByteStreamWrite.

Source

pub fn write_all(&mut self, buffer: &[u8]) -> Result<()>

Wraps AAByteStreamWrite.

Examples found in repository?
examples/11_aa_custom_stream_callbacks.rs (line 102)
99fn main() -> Result<(), Box<dyn std::error::Error>> {
100    let byte_state = Rc::new(RefCell::new(MemoryByteState::default()));
101    let mut stream = ByteStream::custom(SharedByteCallbacks { inner: byte_state })?;
102    stream.write_all(b"hello custom stream")?;
103    stream.seek(0, 0)?;
104    let mut buffer = vec![0_u8; 19];
105    stream.read(&mut buffer)?;
106    assert_eq!(&buffer, b"hello custom stream");
107
108    let archive_state = Rc::new(RefCell::new(MemoryArchiveState::default()));
109    let mut writer = ArchiveStream::custom(SharedArchiveCallbacks {
110        inner: archive_state.clone(),
111    })?;
112    let mut header = Header::new()?;
113    header.append_field_uint(FieldKey::TYP, u64::from(b'F'))?;
114    header.append_field_string(FieldKey::PAT, "custom.txt")?;
115    header.append_field_uint(FieldKey::SIZ, buffer.len() as u64)?;
116    header.append_field_blob(FieldKey::DAT, buffer.len() as u64)?;
117    writer.write_header(&header)?;
118    writer.write_blob(FieldKey::DAT, &buffer)?;
119
120    let mut reader = ArchiveStream::custom(SharedArchiveCallbacks {
121        inner: archive_state,
122    })?;
123    let decoded_header = reader.read_header()?.expect("header");
124    assert_eq!(decoded_header.path()?.as_deref(), Some("custom.txt"));
125    let mut decoded = vec![0_u8; buffer.len()];
126    reader.read_blob(FieldKey::DAT, &mut decoded)?;
127    assert_eq!(decoded, buffer);
128
129    println!("✅ Custom AppleArchive byte/archive stream callbacks OK");
130    Ok(())
131}
More examples
Hide additional examples
examples/10_aea_roundtrip.rs (line 26)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11    let artifact_dir = artifact_dir("aea-roundtrip");
12    let archive_path = path_string(&artifact_dir.join("example.aea"));
13    let payload = pseudo_random_bytes(16 * 1024);
14
15    let mut context = AeaContext::with_profile(AeaProfile::HkdfSha256AesctrHmacSymmetricNone)?;
16    context.set_padding_size(AeaPadding::NONE)?;
17    context.set_compression_algorithm(ArchiveCompressionAlgorithm::Lzfse)?;
18    context.generate_field_blob(AeaContextField::SymmetricKey)?;
19
20    let stream = ByteStream::open_with_path(
21        &archive_path,
22        OPEN_READ_WRITE | OPEN_CREATE | OPEN_TRUNCATE,
23        DEFAULT_FILE_MODE,
24    )?;
25    let mut encrypted = context.encryption_output_stream(stream, ArchiveFlags::empty(), 0)?;
26    encrypted.write_all(&payload)?;
27    context.close_encryption_output_stream(&mut encrypted)?;
28
29    let symmetric_key = context.field_blob(
30        AeaContextField::SymmetricKey,
31        AeaContextFieldRepresentation::Raw,
32    )?;
33    let mut input = ByteStream::open_with_path(&archive_path, OPEN_READ_ONLY, 0)?;
34    let mut decrypt_context = AeaContext::from_encrypted_stream(&mut input)?;
35    decrypt_context.set_symmetric_key(&symmetric_key)?;
36    let mut decrypted = decrypt_context.decryption_input_stream(input, ArchiveFlags::empty(), 0)?;
37    assert_eq!(decrypted.read_to_end()?, payload);
38
39    println!(
40        "raw_size={} container_size={}",
41        context.raw_size()?,
42        context.container_size()?
43    );
44    println!("✅ AppleEncryptedArchive roundtrip OK");
45    Ok(())
46}
Source

pub fn pwrite(&mut self, buffer: &[u8], offset: i64) -> Result<usize>

Wraps AAByteStreamPWrite.

Source

pub fn read(&mut self, buffer: &mut [u8]) -> Result<usize>

Wraps AAByteStreamRead.

Examples found in repository?
examples/11_aa_custom_stream_callbacks.rs (line 105)
99fn main() -> Result<(), Box<dyn std::error::Error>> {
100    let byte_state = Rc::new(RefCell::new(MemoryByteState::default()));
101    let mut stream = ByteStream::custom(SharedByteCallbacks { inner: byte_state })?;
102    stream.write_all(b"hello custom stream")?;
103    stream.seek(0, 0)?;
104    let mut buffer = vec![0_u8; 19];
105    stream.read(&mut buffer)?;
106    assert_eq!(&buffer, b"hello custom stream");
107
108    let archive_state = Rc::new(RefCell::new(MemoryArchiveState::default()));
109    let mut writer = ArchiveStream::custom(SharedArchiveCallbacks {
110        inner: archive_state.clone(),
111    })?;
112    let mut header = Header::new()?;
113    header.append_field_uint(FieldKey::TYP, u64::from(b'F'))?;
114    header.append_field_string(FieldKey::PAT, "custom.txt")?;
115    header.append_field_uint(FieldKey::SIZ, buffer.len() as u64)?;
116    header.append_field_blob(FieldKey::DAT, buffer.len() as u64)?;
117    writer.write_header(&header)?;
118    writer.write_blob(FieldKey::DAT, &buffer)?;
119
120    let mut reader = ArchiveStream::custom(SharedArchiveCallbacks {
121        inner: archive_state,
122    })?;
123    let decoded_header = reader.read_header()?.expect("header");
124    assert_eq!(decoded_header.path()?.as_deref(), Some("custom.txt"));
125    let mut decoded = vec![0_u8; buffer.len()];
126    reader.read_blob(FieldKey::DAT, &mut decoded)?;
127    assert_eq!(decoded, buffer);
128
129    println!("✅ Custom AppleArchive byte/archive stream callbacks OK");
130    Ok(())
131}
Source

pub fn pread(&mut self, buffer: &mut [u8], offset: i64) -> Result<usize>

Wraps AAByteStreamPRead.

Source

pub fn seek(&mut self, offset: i64, whence: i32) -> Result<u64>

Wraps AAByteStreamSeek.

Examples found in repository?
examples/11_aa_custom_stream_callbacks.rs (line 103)
99fn main() -> Result<(), Box<dyn std::error::Error>> {
100    let byte_state = Rc::new(RefCell::new(MemoryByteState::default()));
101    let mut stream = ByteStream::custom(SharedByteCallbacks { inner: byte_state })?;
102    stream.write_all(b"hello custom stream")?;
103    stream.seek(0, 0)?;
104    let mut buffer = vec![0_u8; 19];
105    stream.read(&mut buffer)?;
106    assert_eq!(&buffer, b"hello custom stream");
107
108    let archive_state = Rc::new(RefCell::new(MemoryArchiveState::default()));
109    let mut writer = ArchiveStream::custom(SharedArchiveCallbacks {
110        inner: archive_state.clone(),
111    })?;
112    let mut header = Header::new()?;
113    header.append_field_uint(FieldKey::TYP, u64::from(b'F'))?;
114    header.append_field_string(FieldKey::PAT, "custom.txt")?;
115    header.append_field_uint(FieldKey::SIZ, buffer.len() as u64)?;
116    header.append_field_blob(FieldKey::DAT, buffer.len() as u64)?;
117    writer.write_header(&header)?;
118    writer.write_blob(FieldKey::DAT, &buffer)?;
119
120    let mut reader = ArchiveStream::custom(SharedArchiveCallbacks {
121        inner: archive_state,
122    })?;
123    let decoded_header = reader.read_header()?.expect("header");
124    assert_eq!(decoded_header.path()?.as_deref(), Some("custom.txt"));
125    let mut decoded = vec![0_u8; buffer.len()];
126    reader.read_blob(FieldKey::DAT, &mut decoded)?;
127    assert_eq!(decoded, buffer);
128
129    println!("✅ Custom AppleArchive byte/archive stream callbacks OK");
130    Ok(())
131}
Source

pub fn read_to_end(&mut self) -> Result<Vec<u8>>

Wraps repeated AAByteStreamRead calls.

Examples found in repository?
examples/05_aa_byte_stream_pipeline.rs (line 37)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11    let input = pseudo_random_bytes(32 * 1024);
12    let artifact_dir = artifact_dir("aa-byte-stream");
13    let plain_path = artifact_dir.join("payload.bin");
14    let compressed_path = artifact_dir.join("payload.pbzx");
15    fs::write(&plain_path, &input)?;
16
17    let mut input_stream =
18        ByteStream::open_with_path(&path_string(&plain_path), OPEN_READ_ONLY, 0)?;
19    let compressed_stream = ByteStream::open_with_path(
20        &path_string(&compressed_path),
21        OPEN_WRITE_ONLY | OPEN_CREATE | OPEN_TRUNCATE,
22        DEFAULT_FILE_MODE,
23    )?;
24    let mut compressed_stream = compressed_stream.into_compression_output(
25        ArchiveCompressionAlgorithm::Lzfse,
26        64 * 1024,
27        ArchiveFlags::empty(),
28        0,
29    )?;
30    input_stream.process_into(&mut compressed_stream)?;
31    compressed_stream.close()?;
32
33    let compressed_stream =
34        ByteStream::open_with_path(&path_string(&compressed_path), OPEN_READ_ONLY, 0)?;
35    let mut decompressed_stream =
36        compressed_stream.into_decompression_input(ArchiveFlags::empty(), 0)?;
37    let output = decompressed_stream.read_to_end()?;
38    assert_eq!(output, input);
39    decompressed_stream.close()?;
40
41    let compressed_len = fs::metadata(&compressed_path)?.len();
42    println!("compressed bytes={compressed_len}");
43    println!("✅ AppleArchive byte-stream pipeline OK");
44    Ok(())
45}
More examples
Hide additional examples
examples/10_aea_roundtrip.rs (line 37)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11    let artifact_dir = artifact_dir("aea-roundtrip");
12    let archive_path = path_string(&artifact_dir.join("example.aea"));
13    let payload = pseudo_random_bytes(16 * 1024);
14
15    let mut context = AeaContext::with_profile(AeaProfile::HkdfSha256AesctrHmacSymmetricNone)?;
16    context.set_padding_size(AeaPadding::NONE)?;
17    context.set_compression_algorithm(ArchiveCompressionAlgorithm::Lzfse)?;
18    context.generate_field_blob(AeaContextField::SymmetricKey)?;
19
20    let stream = ByteStream::open_with_path(
21        &archive_path,
22        OPEN_READ_WRITE | OPEN_CREATE | OPEN_TRUNCATE,
23        DEFAULT_FILE_MODE,
24    )?;
25    let mut encrypted = context.encryption_output_stream(stream, ArchiveFlags::empty(), 0)?;
26    encrypted.write_all(&payload)?;
27    context.close_encryption_output_stream(&mut encrypted)?;
28
29    let symmetric_key = context.field_blob(
30        AeaContextField::SymmetricKey,
31        AeaContextFieldRepresentation::Raw,
32    )?;
33    let mut input = ByteStream::open_with_path(&archive_path, OPEN_READ_ONLY, 0)?;
34    let mut decrypt_context = AeaContext::from_encrypted_stream(&mut input)?;
35    decrypt_context.set_symmetric_key(&symmetric_key)?;
36    let mut decrypted = decrypt_context.decryption_input_stream(input, ArchiveFlags::empty(), 0)?;
37    assert_eq!(decrypted.read_to_end()?, payload);
38
39    println!(
40        "raw_size={} container_size={}",
41        context.raw_size()?,
42        context.container_size()?
43    );
44    println!("✅ AppleEncryptedArchive roundtrip OK");
45    Ok(())
46}
Source

pub fn cancel(&mut self) -> Result<()>

Wraps AAByteStreamClose.

Source

pub fn abort(&mut self) -> Result<()>

👎Deprecated since 0.2.2:

Use ByteStream::cancel; AAByteStreamAbort is a deprecated AppleArchive compatibility shim.

Wraps AAByteStreamClose.

Source

pub fn close(&mut self) -> Result<()>

Wraps AAByteStreamClose.

Examples found in repository?
examples/05_aa_byte_stream_pipeline.rs (line 31)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11    let input = pseudo_random_bytes(32 * 1024);
12    let artifact_dir = artifact_dir("aa-byte-stream");
13    let plain_path = artifact_dir.join("payload.bin");
14    let compressed_path = artifact_dir.join("payload.pbzx");
15    fs::write(&plain_path, &input)?;
16
17    let mut input_stream =
18        ByteStream::open_with_path(&path_string(&plain_path), OPEN_READ_ONLY, 0)?;
19    let compressed_stream = ByteStream::open_with_path(
20        &path_string(&compressed_path),
21        OPEN_WRITE_ONLY | OPEN_CREATE | OPEN_TRUNCATE,
22        DEFAULT_FILE_MODE,
23    )?;
24    let mut compressed_stream = compressed_stream.into_compression_output(
25        ArchiveCompressionAlgorithm::Lzfse,
26        64 * 1024,
27        ArchiveFlags::empty(),
28        0,
29    )?;
30    input_stream.process_into(&mut compressed_stream)?;
31    compressed_stream.close()?;
32
33    let compressed_stream =
34        ByteStream::open_with_path(&path_string(&compressed_path), OPEN_READ_ONLY, 0)?;
35    let mut decompressed_stream =
36        compressed_stream.into_decompression_input(ArchiveFlags::empty(), 0)?;
37    let output = decompressed_stream.read_to_end()?;
38    assert_eq!(output, input);
39    decompressed_stream.close()?;
40
41    let compressed_len = fs::metadata(&compressed_path)?.len();
42    println!("compressed bytes={compressed_len}");
43    println!("✅ AppleArchive byte-stream pipeline OK");
44    Ok(())
45}
Source

pub fn process_into(&mut self, output: &mut Self) -> Result<u64>

Wraps AAByteStreamProcess.

Examples found in repository?
examples/05_aa_byte_stream_pipeline.rs (line 30)
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11    let input = pseudo_random_bytes(32 * 1024);
12    let artifact_dir = artifact_dir("aa-byte-stream");
13    let plain_path = artifact_dir.join("payload.bin");
14    let compressed_path = artifact_dir.join("payload.pbzx");
15    fs::write(&plain_path, &input)?;
16
17    let mut input_stream =
18        ByteStream::open_with_path(&path_string(&plain_path), OPEN_READ_ONLY, 0)?;
19    let compressed_stream = ByteStream::open_with_path(
20        &path_string(&compressed_path),
21        OPEN_WRITE_ONLY | OPEN_CREATE | OPEN_TRUNCATE,
22        DEFAULT_FILE_MODE,
23    )?;
24    let mut compressed_stream = compressed_stream.into_compression_output(
25        ArchiveCompressionAlgorithm::Lzfse,
26        64 * 1024,
27        ArchiveFlags::empty(),
28        0,
29    )?;
30    input_stream.process_into(&mut compressed_stream)?;
31    compressed_stream.close()?;
32
33    let compressed_stream =
34        ByteStream::open_with_path(&path_string(&compressed_path), OPEN_READ_ONLY, 0)?;
35    let mut decompressed_stream =
36        compressed_stream.into_decompression_input(ArchiveFlags::empty(), 0)?;
37    let output = decompressed_stream.read_to_end()?;
38    assert_eq!(output, input);
39    decompressed_stream.close()?;
40
41    let compressed_len = fs::metadata(&compressed_path)?.len();
42    println!("compressed bytes={compressed_len}");
43    println!("✅ AppleArchive byte-stream pipeline OK");
44    Ok(())
45}
Source

pub fn process_random_access_into( &mut self, output: &mut Self, max_offset: i64, block_size: usize, flags: ArchiveFlags, n_threads: i32, ) -> Result<u64>

Wraps AARandomAccessByteStreamProcess.

Source§

impl ByteStream

Source

pub fn custom<T: CustomByteStreamCallbacks + 'static>( callbacks: T, ) -> Result<Self>

Wraps AACustomByteStreamOpen.

Examples found in repository?
examples/11_aa_custom_stream_callbacks.rs (line 101)
99fn main() -> Result<(), Box<dyn std::error::Error>> {
100    let byte_state = Rc::new(RefCell::new(MemoryByteState::default()));
101    let mut stream = ByteStream::custom(SharedByteCallbacks { inner: byte_state })?;
102    stream.write_all(b"hello custom stream")?;
103    stream.seek(0, 0)?;
104    let mut buffer = vec![0_u8; 19];
105    stream.read(&mut buffer)?;
106    assert_eq!(&buffer, b"hello custom stream");
107
108    let archive_state = Rc::new(RefCell::new(MemoryArchiveState::default()));
109    let mut writer = ArchiveStream::custom(SharedArchiveCallbacks {
110        inner: archive_state.clone(),
111    })?;
112    let mut header = Header::new()?;
113    header.append_field_uint(FieldKey::TYP, u64::from(b'F'))?;
114    header.append_field_string(FieldKey::PAT, "custom.txt")?;
115    header.append_field_uint(FieldKey::SIZ, buffer.len() as u64)?;
116    header.append_field_blob(FieldKey::DAT, buffer.len() as u64)?;
117    writer.write_header(&header)?;
118    writer.write_blob(FieldKey::DAT, &buffer)?;
119
120    let mut reader = ArchiveStream::custom(SharedArchiveCallbacks {
121        inner: archive_state,
122    })?;
123    let decoded_header = reader.read_header()?.expect("header");
124    assert_eq!(decoded_header.path()?.as_deref(), Some("custom.txt"));
125    let mut decoded = vec![0_u8; buffer.len()];
126    reader.read_blob(FieldKey::DAT, &mut decoded)?;
127    assert_eq!(decoded, buffer);
128
129    println!("✅ Custom AppleArchive byte/archive stream callbacks OK");
130    Ok(())
131}

Trait Implementations§

Source§

impl Debug for ByteStream

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for ByteStream

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.