I am using Grit (Ruby gem) to load a git repo, extract a given commit to a folder, then ‘do stuff’ with it. Grit supports git archive with archive_tar which retuns a ‘string containing tar archive’. I would like to extract this to the filesystem using Ruby libs / gems if possible (not direct system calls) and avoid things like saving the data to an archive first and then extracting it (really looking for an efficient one-liner here).
Share
Under the assumption that ‘string containing tar archive’ is equivalent to
File.open("Downloads.tar", "rb") {|a| a.read }I am able to accomplish this using fileutils, stringio, and the minitar gem.
First you will need to install minitar, which should be as simple as
Since minitar does not support it’s regular unpack to use a stream, we’ll create our own rudimentary unpacking method.
Of course replacing the whole File.open part with the
archive_tarfunction of the Grit gem. This is all assuming that first assumption of course, though i’m sure ths method can easily be adapted to suit whateverarchive_taractually returns.