github.com/hkalexling/archive.cr

libarchive bindings for Crystal

3 stars
1 dependent
License: MIT

Installation

# Add this to your shard.yml
dependencies:
  archive:
    github: hkalexling/archive.cr
    version: ~> 0.5.0

Then run:

shards install

shard.yml

Crystal
1.0.0
License
MIT
Author
Alex Ling <hkalexling@gmail.com>

Dependencies

This version declares no dependencies.

README

# archive.cr

![CI](https://github.com/hkalexling/archive.cr/workflows/CI/badge.svg)

`archive.cr` provides [libarchive](https://github.com/libarchive/libarchive) bindings for Crystal. Only a small subset of the libarchive functions are implemented, and currently only extraction is supported.

## Installation

1. Add the dependency to your `shard.yml`:

   ```yaml
   dependencies:
     archive:
       github: hkalexling/archive.cr
   ```

2. Run `shards install`

## Usage

```crystal
require "archive"

# Extract all entries
Archive::File.open "file.zip" do |f|
  f.entries.map do |e|
    # Skip non-file entries
  	next unless e.info.file?

    filename = e.filename
    size = e.size
    file = File.new filename, "wb"
    file.write e.read
  end
end

# Extract a specific entry
Archive::File.open "file.zip" do |f|
    file = File.new "img.jpg", "wb"
    file.write f.read_entry "img.jpg"
end
```