untar
Version, currently master branch1 version
- master branchlatestMar 3, 2019
github.com/vivus-ignis/crystal-untar
Minimalistic libtar-based library that can extract tar archives from a file on disk or from a memory buffer
Installation
# Add this to your shard.yml
dependencies:
untar:
github: vivus-ignis/crystal-untar
branch: mastermaster is a branch, not a release, so this tracks it rather than pinning a version.
Then run:
shards installshard.yml
- Crystal
0.27.2- License
- MIT
- Author
- your-name-here <your-email-here>
Dependencies
This version declares no dependencies.
README
untar
Minimalistic libtar-based library that can extract tar archives from a file on disk or from a memory buffer.
Installation
-
Make sure libtar is available on your system.
-
Add the dependency to your
shard.yml:dependencies: untar: github: vivus-ignis/crystal-untar -
Run
shards install
Usage
There are two ways to use this library. Obviously, you can extract files from a tar archive on disk:
require "untar"
Dir.mkdir "/tmp/archive"
Untar.extract("archive.tar", "/tmp/archive")
The other option is to extract files from an archive that is loaded in a memory buffer. Consider the example below:
require "http/client"
require "gzip"
require "untar"
response = HTTP::Client.get "https://nginx.org/download/nginx-1.15.9.tar.gz"
zipped = IO::Memory.new(response.body)
unzipped = Gzip::Reader.open(zipped) { |gzip| gzip.gets_to_end }
tarball = IO::Memory.new(unzipped)
Dir.mkdir "/tmp/nginx"
Untar.extract(tarball, "/tmp/nginx")
Notice that the same Untar.extract method is used to unpack a
tarball on disk and in memory.
For an in-memory archive there is an additional option to only extract a certain file. Let's pretend we want to fetch nginx changelog:
require "http/client"
require "gzip"
require "untar"
response = HTTP::Client.get "https://nginx.org/download/nginx-1.15.9.tar.gz"
zipped = IO::Memory.new(response.body)
unzipped = Gzip::Reader.open(zipped) { |gzip| gzip.gets_to_end }
tarball = IO::Memory.new(unzipped)
changelog = Untar.extract_file(tarball, "nginx-1.15.9/CHANGES")
puts changelog
Error handling
On errors Untar raises an UntarException.
Contributing
- Fork it (https://github.com/vivus-ignis/crystal-untar/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- Yaroslav Tarasenko - creator and maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This branch
- Branch
master- Seen
- Mar 3, 2019
- Crystal
0.27.2- Indexed
- yes
Dependents
No indexed shard depends on this one yet.
Repository
github.com/vivus-ignis/crystal-untar
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 15, 2026
- Synced
- Aug 15, 2026
- Versions
- 1