Skip to content

Commit eb1b586

Browse files
romualdPr0methean
andauthored
docs: Update zip_writer documentation example (#431)
* Update zip_writer documentation example Replace the fixed size buffer example with a dynamic Vec Since the buffer size was of fixed, size, the resulting zip file was always the same size, defeating the purpose of compression * Comment inside an example needs "/// //" Signed-off-by: Chris Hennick <[email protected]> --------- Signed-off-by: Chris Hennick <[email protected]> Co-authored-by: Chris Hennick <[email protected]>
1 parent 26e6e08 commit eb1b586

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/write.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ pub(crate) mod zip_writer {
143143
/// use std::io::Write;
144144
/// use zip::write::SimpleFileOptions;
145145
///
146-
/// // We use a buffer here, though you'd normally use a `File`
147-
/// let mut buf = [0; 65536];
148-
/// let mut zip = ZipWriter::new(std::io::Cursor::new(&mut buf[..]));
146+
/// // We use a cursor + vec here, though you'd normally use a `File`
147+
/// let mut cur = std::io::Cursor::new(Vec::new());
148+
/// let mut zip = ZipWriter::new(&mut cur);
149149
///
150150
/// let options = SimpleFileOptions::default().compression_method(zip::CompressionMethod::Stored);
151151
/// zip.start_file("hello_world.txt", options)?;
@@ -155,6 +155,9 @@ pub(crate) mod zip_writer {
155155
/// // Dropping the `ZipWriter` will have the same effect, but may silently fail
156156
/// zip.finish()?;
157157
///
158+
/// // raw zip data is available as a Vec<u8>
159+
/// let zip_bytes = cur.into_inner();
160+
///
158161
/// # Ok(())
159162
/// # }
160163
/// # doit().unwrap();

0 commit comments

Comments
 (0)