Skip to content

Commit d76e609

Browse files
Merge pull request marshallpierce#167 from marshallpierce/mp/expose-encoded-len
Expose encoded_len function
2 parents e3525bb + e783e04 commit d76e609

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

RELEASE-NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Since there are already multiple breaking changes, various functions are renamed to be more consistent and discoverable.
99
- MSRV is now 1.47.0 to allow various things to use `const fn`.
1010
- `DecoderReader` now owns its inner reader, and can expose it via `into_inner()`. For symmetry, `EncoderWriter` can do the same with its writer.
11+
- `encoded_len` is now public so you can size encode buffers precisely.
1112

1213
# 0.13.0
1314

src/encode.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,10 @@ fn encode_with_padding<E: Engine>(
191191
debug_assert_eq!(expected_encoded_size, encoded_bytes);
192192
}
193193

194-
/// calculate the base64 encoded string size, including padding if appropriate
194+
/// Calculate the base64 encoded length for a given input length, optionally including any
195+
/// appropriate padding bytes.
196+
///
197+
/// Returns `None` if the encoded length can't be represented in `usize`.
195198
pub fn encoded_len(bytes_len: usize, padding: bool) -> Option<usize> {
196199
let rem = bytes_len % 3;
197200

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ pub mod engine;
109109
pub mod alphabet;
110110

111111
mod encode;
112-
pub use crate::encode::encode_engine_slice;
113112
#[cfg(any(feature = "alloc", feature = "std", test))]
114113
pub use crate::encode::{encode, encode_engine, encode_engine_string};
114+
pub use crate::encode::{encode_engine_slice, encoded_len};
115115

116116
mod decode;
117117
#[cfg(any(feature = "alloc", feature = "std", test))]

0 commit comments

Comments
 (0)