Add the following code to your project's shard.yml under:
dependencies
to use in production
- OR -
development_dependencies
to use in development
This shard makes you to read the TAR archive files(POSIX ustar format and some functions in GNUTAR fomat).
No external library needed. This is written in pure Crystal.
In this version, following entry types are supported:
'\0'
or '0'
)'1'
)'2'
)'5'
)'x'
) (mtime, path, linkpath, uid, gid)'L'
)'K'
)Other entry type will be extracted as a regular file.
Supporting gzipped tar archive file.
Add the dependency to your shard.yml
:
dependencies:
tarball:
github: arcage/tarball.cr
Then, run shards install
require "tarball"
# Extracts all files in "archive.tar" to under the "data" directory.
Tarball.extract_all("archive.tar", "data")
Tarball.open("archive.tar") do |tar|
# list of included file system objects.
tar.filenames
#=> ["dir/", "dir/file_name.txt", "dir/image.png"]
# extract specific file to specific path.
tar.extract_file("dir/file_name.txt", "other_name.txt")
# write content data to IO object.
tar.write_content("dir/file_name.txt", STDOUT)
end
# open gzipped tar archive
Tarball.open_gz("archive.tar.gz") do |tar|
# ...
end