{"id":22820144,"url":"https://github.com/kizzycode/basic_tar","last_synced_at":"2025-03-30T23:16:25.767Z","repository":{"id":57503377,"uuid":"200560485","full_name":"KizzyCode/basic_tar","owner":"KizzyCode","description":"Building blocks to read and write classic oldstyle tar archives and streams","archived":false,"fork":false,"pushed_at":"2019-08-05T01:55:42.000Z","size":15,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-09T12:02:14.756Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","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/KizzyCode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE BSD 2-CLAUSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-05T01:18:54.000Z","updated_at":"2023-11-03T07:08:17.000Z","dependencies_parsed_at":"2022-09-13T08:22:10.431Z","dependency_job_id":null,"html_url":"https://github.com/KizzyCode/basic_tar","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KizzyCode%2Fbasic_tar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KizzyCode%2Fbasic_tar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KizzyCode%2Fbasic_tar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KizzyCode%2Fbasic_tar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KizzyCode","download_url":"https://codeload.github.com/KizzyCode/basic_tar/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246390858,"owners_count":20769478,"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-12T15:16:36.511Z","updated_at":"2025-03-30T23:16:25.741Z","avatar_url":"https://github.com/KizzyCode.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![docs.rs](https://docs.rs/basic_tar/badge.svg)](https://docs.rs/basic_tar)\n[![License BSD-2-Clause](https://img.shields.io/badge/License-BSD--2--Clause-blue.svg)](https://opensource.org/licenses/BSD-2-Clause)\n[![License MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n[![crates.io](https://img.shields.io/crates/v/basic_tar.svg)](https://crates.io/crates/basic_tar)\n[![Download numbers](https://img.shields.io/crates/d/basic_tar.svg)](https://crates.io/crates/basic_tar)\n[![Travis CI](https://travis-ci.org/KizzyCode/basic_tar.svg?branch=master)](https://travis-ci.org/KizzyCode/basic_tar)\n[![AppVeyor CI](https://ci.appveyor.com/api/projects/status/github/KizzyCode/basic_tar?svg=true)](https://ci.appveyor.com/project/KizzyCode/basic-tar)\n[![dependency status](https://deps.rs/crate/basic_tar/0.1.1/status.svg)](https://deps.rs/crate/basic_tar/0.1.1)\n\n# basic_tar\nWelcome to `basic_tar` 🎉\n\n\n## About\nThis crate provides some functionality to read and write __basic/classic oldstyle__ tar archives and\nsome extensions for `io::Read` and `io::Write` to make it easier to work with tar streams.\n\n_Note: It is not intended as an high-level allround (un-)packer but as a building block of you want\nto use the tar format for your own applications – for a high-level solution, take a look at_\n[`tar`](https://crates.io/crates/tar)\n\n\n## How to read a stream\nTo read a tar record from an archive stream, you need to read\n 1. the header for the next record\n 2. the payload\n 3. the padding bytes which pad the payload to a multiple of the block size (512 byte)\n\n### Example:\n```rust\nuse std::{ convert::TryFrom, error::Error, io::Read };\nuse basic_tar::{\n\tReadExt, U64Ext, Header,\n\traw::{ self, BLOCK_LEN }\n};\n\n/// Reads the next record from `stream`\nfn read_next(mut stream: impl Read) -\u003e Result\u003c(Header, Vec\u003cu8\u003e), Box\u003cdyn Error + 'static\u003e\u003e {\n\t// Read the header\n\tlet mut header_raw = raw::header::raw();\n\tstream.read_exact(\u0026mut header_raw)?;\n\n\t// Parse the header and get the payload lengths\n\tlet header = Header::parse(header_raw)?;\n\tlet payload_len = header.size;\n\tlet payload_total_len = payload_len.ceil_to_multiple_of(BLOCK_LEN as u64);\n\n\t// Read the payload\n\tlet mut payload = vec![0; usize::try_from(payload_len)?];\n\tstream.read_exact(\u0026mut payload)?;\n\n\t// Drain the padding and return the record\n\tlet padding_len = usize::try_from(payload_total_len - payload_len)?;\n\tstream.try_drain(padding_len, |_| {})?;\n\tOk((header, payload))\n}\n```\n\n\n## How to write a stream\nTo write a tar record to an archive stream, you need to write\n 1. your header\n 2. your payload\n 3. the padding bytes to pad your payload to a multiple of the block size (512 byte)\n\n### Example:\n```rust\nuse std::{ convert::TryFrom, error::Error, io::Write };\nuse basic_tar::{ WriteExt, U64Ext, Header, raw::BLOCK_LEN };\n\n/// Writes `header` and `payload` to `stream`\nfn write_next(header: Header, payload: \u0026[u8], mut stream: impl Write)\n\t-\u003e Result\u003c(), Box\u003cdyn Error + 'static\u003e\u003e\n{\n\t// Serialize the header and write it and the payload\n\tlet header_raw = header.serialize()?;\n\tstream.write_all(\u0026header_raw)?;\n\tstream.write_all(payload)?;\n\n\t// Write the padding\n\tlet payload_len = payload.len() as u64;\n\tlet padding_len = payload_len.ceil_to_multiple_of(BLOCK_LEN as u64) - payload_len;\n\tstream.try_fill(usize::try_from(padding_len)?, |_| {})?;\n\n\tOk(())\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkizzycode%2Fbasic_tar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkizzycode%2Fbasic_tar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkizzycode%2Fbasic_tar/lists"}