Extract contents of single file from a tar archive

I'm just learning Rust, and trying to use the tar crate to extract a single file from a tar archive.

I'm wondering if there is a way to extract the contents of a single file from the tar archive without writing the file to disk. Does anyone know if that is possible?

As far as I can tell, it seems like the unpack functions all expect a Path, assuming that you want to write the contents of the file to disk somewhere.

For Example

Say I have a .tar with a bunch of files in it, but I just need one .json or .csv file in there. I don't need to write that file to disk, I just need to use the data in that file to do some other stuff.

Writing the file to disk wouldn't be the end of the world, but since this is Rust, I figured there might be a way to avoid that I/O :slight_smile:

tar::Entry implements Read, so you can iterate over the archive's entries and read the relevant file's contents with something like Read::read_to_string.


Ah of course! So wonderfully simple. Thank you!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.