{"id":18103152,"url":"https://github.com/philr/bzip2-ffi","last_synced_at":"2025-04-13T19:08:50.923Z","repository":{"id":25356172,"uuid":"28783883","full_name":"philr/bzip2-ffi","owner":"philr","description":"Ruby library that reads and writes bzip2 compressed data as a stream using FFI bindings for libbz2.","archived":false,"fork":false,"pushed_at":"2024-04-18T12:21:12.000Z","size":293,"stargazers_count":6,"open_issues_count":2,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-25T01:21:30.623Z","etag":null,"topics":["bz2","bzip2","compression","decompression","ffi","libbz2","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/philr.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-01-04T19:36:47.000Z","updated_at":"2024-06-19T20:02:41.546Z","dependencies_parsed_at":"2023-12-16T20:31:51.756Z","dependency_job_id":"32df1f8d-0dbe-4cd7-bafe-75319470f725","html_url":"https://github.com/philr/bzip2-ffi","commit_stats":{"total_commits":124,"total_committers":1,"mean_commits":124.0,"dds":0.0,"last_synced_commit":"04ad42f54d9ae4b8cb7ff1c1d6646c6a0aca4e25"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/philr%2Fbzip2-ffi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/philr%2Fbzip2-ffi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/philr%2Fbzip2-ffi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/philr%2Fbzip2-ffi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/philr","download_url":"https://codeload.github.com/philr/bzip2-ffi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248766746,"owners_count":21158301,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bz2","bzip2","compression","decompression","ffi","libbz2","ruby"],"created_at":"2024-10-31T22:10:37.030Z","updated_at":"2025-04-13T19:08:50.891Z","avatar_url":"https://github.com/philr.png","language":"Ruby","readme":"# Bzip2::FFI\n\n[![RubyGems](https://img.shields.io/gem/v/bzip2-ffi?logo=rubygems\u0026label=Gem)](https://rubygems.org/gems/bzip2-ffi) [![Tests](https://github.com/philr/bzip2-ffi/workflows/Tests/badge.svg?branch=master\u0026event=push)](https://github.com/philr/bzip2-ffi/actions?query=workflow%3ATests+branch%3Amaster+event%3Apush) [![Coverage Status](https://img.shields.io/coveralls/github/philr/bzip2-ffi/master?label=Coverage\u0026logo=Coveralls)](https://coveralls.io/github/philr/bzip2-ffi?branch=master)\n\nBzip2::FFI is a Ruby wrapper for libbz2 using FFI bindings.\n\nThe Bzip2::FFI Reader and Writer classes support reading and writing bzip2\ncompressed data as an `IO`-like stream.\n\n\n## Installation\n\nThe Bzip2::FFI gem can be installed by running `gem install bzip2-ffi` or by\nadding `gem 'bzip2-ffi'` to your `Gemfile` and running `bundle install`.\n\n\n## Compatibility\n\nBzip2::FFI requires a minimum of Ruby MRI 1.9.3 or JRuby 1.7 (in 1.9 mode or\nlater).\n\n\n## Runtime Dependencies\n\nBzip2::FFI is a pure-Ruby library that uses\n[Ruby-FFI](https://rubygems.org/gems/ffi) (Foreign Function Interface) to load\nthe libbz2 dynamic library at runtime.\n\nlibbz2 is available as a package on most UNIX-based systems (for example,\n`libbz2-1.0` on Debian and Ubuntu, or `bzip2-libs` on Fedora, Red Hat and\nCentOS).\n\n\n### Windows\n\nOn Windows, you will need to have `libbz2.dll` or `bz2.dll` available on the\n`PATH` or in the Ruby `bin` directory.\n\nSuitable builds of `libbz2.dll` are available from the\n[bzip2-windows project](https://github.com/philr/bzip2-windows/releases).\nDownload the DLL only package that matches your Ruby installation (x86 or x64)\nand extract to your `ruby\\bin` directory.\n\nBuilds from the bzip2-windows project depend on the Visual Studio C Runtime\nLibrary. Links to the installer can be found on the bzip2-windows releases page.\n\n\n## Usage\n\nTo use Bzip2::FFI, it must first be loaded with:\n\n```ruby\nrequire 'bzip2/ffi'\n```\n\n\n### Compressing\n\nData can be compressed using the `Bzip2::FFI::Writer` class. For example, the\nfollowing compresses lines read from `ARGF` (either standard input, or file\nnames given as command-line arguments):\n\n```ruby\nBzip2::FFI::Writer.open(io_or_path) do |writer|\n  ARGF.each_line do |line|\n    writer.write(line)\n  end\nend\n```\n\nAlternatively, without passing a block to `open`:\n\n```ruby\nwriter = Bzip2::FFI::Writer.open(io_or_path)\nbegin\n  ARGF.each_line do |line|\n    writer.write(line)\n  end\nensure\n  writer.close\nend\n```\n\nAn entire bzip2 structure can also be written in a single step:\n\n```ruby\nBzip2::FFI::Writer.write(io_or_path, 'Hello, World!')\n```\n\nIn each of the examples above, `io_or_path` can either be a path to a file to\nwrite to or an `IO`-like object that has a `#write` method.\n\n\n### Decompressing\n\nData can be decompressed using the `Bzip2::FFI::Reader` class. For example:\n\n```ruby\nBzip2::FFI::Reader.open(io_or_path) do |reader|\n  while buffer = reader.read(1024) do\n    # process uncompressed bytes in buffer\n  end\nend\n```\n\nAlternatively, without passing a block to `open`:\n\n```ruby\nreader = Bzip2::FFI::Reader.open(io_or_path)\nbegin\n  while buffer = reader.read(1024) do\n    # process uncompressed bytes in buffer\n  end\nensure\n  reader.close\nend\n```\n\nAll the available bzipped data can also be read and decompressed in a single\nstep:\n\n```ruby\nuncompressed = Bzip2::FFI::Reader.read(io_or_path)\n```\n\nIn each of the examples above, `io_or_path` can either be a path to a file to\nread from or an `IO`-like object that has a `#read` method.\n\n\n### Character Encoding\n\nBzip2::FFI does not perform any encoding conversion when reading or writing.\nData read using `Bzip2::FFI::Reader` is returned as `String` instances with\nASCII-8BIT (BINARY) encoding representing the raw decompressed bytes.\n`Bzip2::FFI::Writer` compresses the raw bytes from the `String` instances passed\nto the `#write` method (using the encoding of the `String`).\n\n\n### Streaming and Memory Usage\n\nBzip2::FFI compresses and decompresses data as a stream, allowing large files to\nbe handled without requiring the complete contents to be held in memory.\n\nWhen decompressing, 4 KB of compressed data is read at a time. An additional 4\nKB is required to pass the data to libbz2. Decompressed data is output in blocks\ndictated by the length passed to `Bzip2::FFI::Reader#read` (defaulting to 4 KB\nand requiring twice the length in memory to read from libbz2).\n\nWhen compressing, up to 4 KB of compressed data is written at a time, requiring\nup to 8 KB of memory. An additional copy is also taken of the `String` passed to\n`Bzip2::FFI::Writer#write`.\n\nInternally, libbz2 allocates additional memory according to the bzip2 block\nsize. Please refer to the\n[Memory Management](https://sourceware.org/bzip2/manual/manual.html#memory-management)\nsection of the Bzip2 documentation for details.\n\n\n## Documentation\n\nDocumentation for Bzip2::FFI is available on\n[RubyDoc.info](https://www.rubydoc.info/gems/bzip2-ffi).\n\n\n## License\n\nBzip2::FFI is distributed under the terms of the MIT license. A copy of this\nlicense can be found in the included LICENSE file.\n\n\n## GitHub Project\n\nSource code, release information and the issue tracker can be found on the\n[Bzip2::FFI GitHub project page](https://github.com/philr/bzip2-ffi).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphilr%2Fbzip2-ffi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphilr%2Fbzip2-ffi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphilr%2Fbzip2-ffi/lists"}