{"id":22354275,"url":"https://github.com/jonmagic/tardotgz","last_synced_at":"2025-03-26T12:40:37.269Z","repository":{"id":27709041,"uuid":"31195971","full_name":"jonmagic/tardotgz","owner":"jonmagic","description":"Archive utility module","archived":false,"fork":false,"pushed_at":"2015-02-23T07:02:18.000Z","size":168,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-02T03:11:20.984Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonmagic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-23T05:57:45.000Z","updated_at":"2021-06-29T21:35:44.000Z","dependencies_parsed_at":"2022-09-03T03:43:06.031Z","dependency_job_id":null,"html_url":"https://github.com/jonmagic/tardotgz","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonmagic%2Ftardotgz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonmagic%2Ftardotgz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonmagic%2Ftardotgz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonmagic%2Ftardotgz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonmagic","download_url":"https://codeload.github.com/jonmagic/tardotgz/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245658958,"owners_count":20651517,"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":[],"created_at":"2024-12-04T13:12:10.291Z","updated_at":"2025-03-26T12:40:37.250Z","avatar_url":"https://github.com/jonmagic.png","language":"Ruby","readme":"# Tardotgz\n\nTardotgz is an extraction of a few archive utility methods I wrote while working on a project at GitHub. These methods simplify the creation of gzipped tarball archives and the reading and extraction of files from those archives.\n\nOne of the unique features of the #read_from_archive and #extract_from_archive utility methods is the ability to pass them a block (in fact `#extract_from_archive` just calls `#read_from_archive` and passes it a block).\n\nAnd in case you were wondering, I've been pronouncing it \"tar-dot-jeez\" :grin:\n\n## Installation\n\nYou can install at the command line:\n\n```bash\n$ gem install tardotgz\n```\n\nOr add the gem to your Gemfile:\n\n```ruby\nsource \"https://rubygems.org\"\n\ngem \"tardotgz\"\n```\n\n## Usage\n\nStart by including the module into the class where you'll use it.\n\n```ruby\nrequire \"tardotgz\"\n\nclass FruitRollup\n  include Tardotgz\nend\n```\n\n### Create an archive\n\nCreate an archive from a folder by calling `#create_archive` with the source path (the directory or file you want to archive) and the target path (the path and filename for the archive that it creates).\n\n```ruby\n\u003e fr = FruitRollup.new\n=\u003e #\u003cFruitRollup:0x007fc0e4acf538\u003e\n\u003e source_path = File.expand_path(\"~/Notes\")\n=\u003e \"/Users/jonmagic/Notes\"\n\u003e archive_path = File.expand_path(\"~/Dropbox/notes.tar.gz\")\n=\u003e \"/Users/jonmagic/Dropbox/notes.tar.gz\"\n\u003e fr.create_archive(source_path, archive_path)\n=\u003e \"/Users/jonmagic/Dropbox/notes.tar.gz\"\n```\n\n### Read file(s) from an archive\n\nYou can read the contents of a file (or files) in an archive without unzipping or untarring the archive by using the `#read_from_archive` method. It's use is also fairly flexible.\n\n#### Read the contents of a single file\n\n```ruby\n\u003e fr.read_from_archive(archive_path, \"testing1.md\")\n=\u003e \"hello world\\n\"\n```\n\n#### Read the contents of files matching a pattern\n\n```ruby\n\u003e fr.read_from_archive(archive_path, /testing\\d.md/) # read all files matching pattern\n=\u003e \"hello world\\nfoobarbaz\\n\"\n```\n\n#### Passing a block yields the block with each tarfile that matches the pattern\n\n```ruby\n\u003e fr.read_from_archive(archive_path, /testing\\d.md/) do |tarfile| # pass a block\n*   puts tarfile.read.upcase\n* end\nHELLO WORLD\n\nFOOBARBAZ\n\n=\u003e nil\n```\n\n### Extract file(s) from an archive\n\nYou can extract the contents of an archive with #extract_from_archive.\n\n#### Extract a single file\n\n```ruby\n\u003e destination_path = File.expand_path(\"~/Restored notes\")\n=\u003e \"/Users/jonmagic/Restored notes\"\n\u003e fr.extract_from_archive(archive_path, destination_path, \"testing1.md\")\n=\u003e \"/Users/jonmagic/Restored notes\"\n\u003e File.exist?(\"#{destination_path}/testing1.md\")\n=\u003e true\n\u003e File.exist?(\"#{destination_path}/testing2.md\")\n=\u003e false\n```\n\n#### Extract all files matching a pattern\n\n```ruby\n\u003e fr.extract_from_archive(archive_path, destination_path, /testing\\d\\.md/)\n=\u003e \"/Users/jonmagic/Restored notes\"\n\u003e File.exist?(\"#{destination_path}/testing1.md\")\n=\u003e true\n\u003e File.exist?(\"#{destination_path}/testing2.md\")\n=\u003e true\n```\n\n#### Passing a block cleans up extracted files after extracting and then yielding the block\n\n```ruby\n\u003e fr.extract_from_archive(archive_path, destination_path, /testing\\d\\.md/) do\n*   puts File.exist?(\"#{destination_path}/testing1.md\")\n*   puts File.exist?(\"#{destination_path}/testing2.md\")\n* end\ntrue\ntrue\n=\u003e nil\n\u003e File.exist?(destination_path)\n=\u003e false\n```\n\n## Contribute\n\nIf you'd like to hack on Tardotgz, start by forking the repo on GitHub:\n\nhttps://github.com/jonmagic/tardotgz\n\nThe best way to get your changes merged back into core is as follows:\n\n1. Clone down your fork\n1. Create a thoughtfully named topic branch to contain your change\n1. Hack away\n1. If you are adding new functionality, document it in the README\n1. If necessary, rebase your commits into logical chunks, without errors\n1. Push the branch up to GitHub\n1. Send a pull request for your branch\n\n## LICENSE\n\nThe MIT License (MIT)\n\nCopyright (c) 2015 Jonathan Hoyt\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonmagic%2Ftardotgz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonmagic%2Ftardotgz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonmagic%2Ftardotgz/lists"}