<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Iván Naranjo Ortega</title>
    <description>The latest articles on Forem by Iván Naranjo Ortega (@ivannaranjo999).</description>
    <link>https://forem.com/ivannaranjo999</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3909543%2F5c3bc8af-744d-4ede-99dc-15bd64b3000e.jpeg</url>
      <title>Forem: Iván Naranjo Ortega</title>
      <link>https://forem.com/ivannaranjo999</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ivannaranjo999"/>
    <language>en</language>
    <item>
      <title>I build a simple file archiver in C, SAR</title>
      <dc:creator>Iván Naranjo Ortega</dc:creator>
      <pubDate>Sun, 03 May 2026 08:26:44 +0000</pubDate>
      <link>https://forem.com/ivannaranjo999/i-build-a-simple-file-archiver-in-c-sar-535b</link>
      <guid>https://forem.com/ivannaranjo999/i-build-a-simple-file-archiver-in-c-sar-535b</guid>
      <description>&lt;p&gt;I wanted to sharpen my file management skills in C, not just reading and writing, but also creating, seeking, metadata preservation and compression/decompression with &lt;strong&gt;zlib&lt;/strong&gt;. So I built &lt;strong&gt;SAR&lt;/strong&gt; (&lt;strong&gt;Simple ARchiver&lt;/strong&gt;), a command-line tool to pack and unpack files and directories to a single archive, with optional gzip compression.&lt;/p&gt;

&lt;p&gt;It's heavily inspired by &lt;em&gt;tar&lt;/em&gt;, but stripped down to the essentials. Just a clean binary and a list of focused actions to perform in this archives, compressed or not.&lt;/p&gt;

&lt;h2&gt;
  
  
  The format
&lt;/h2&gt;

&lt;p&gt;The archive, &lt;code&gt;.sar&lt;/code&gt; format, is just a binary file which consists of a secuence of blocks:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;[ FileHeader | raw bytes ][ FileHeader | raw bytes ] ...&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Each &lt;code&gt;FileHeader&lt;/code&gt; is a fixed-size C struct that stores the filename, file size, permissions and modification timestamp. To read the archive you just walk it linearly: read header, skip forward by file size bytes and repeat until EOF.&lt;/p&gt;

&lt;h2&gt;
  
  
  Compression
&lt;/h2&gt;

&lt;p&gt;When using &lt;code&gt;pz&lt;/code&gt;, SAR compresses the entire archive using zlib's deflate into a standard gzip envelope, the same format produce by &lt;code&gt;gzip&lt;/code&gt; tool. This means you can actually decompress SAR compressed files, &lt;code&gt;.sgz&lt;/code&gt; or &lt;code&gt;.sar.gz&lt;/code&gt;, with &lt;code&gt;gunzip&lt;/code&gt; if desired.&lt;/p&gt;

&lt;p&gt;Compression if applied to the whole SAR archive after packing, not per file. This gives better compression ratios.&lt;/p&gt;

&lt;p&gt;For all other actions, SAR detects whether the archive is compressed or not.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dependencies
&lt;/h2&gt;

&lt;p&gt;The only dependency is zlib. &lt;/p&gt;

&lt;h2&gt;
  
  
  Final thoughts
&lt;/h2&gt;

&lt;p&gt;This project is &lt;a href="https://github.com/ivannaranjo999/sar" rel="noopener noreferrer"&gt;on Github&lt;/a&gt;, feedback is very welcome! 🐦.&lt;/p&gt;

&lt;p&gt;Happy to answer questions about the implementation, this was a great exercise in low-level file management and I am starting to use it as an real alternative to &lt;code&gt;tar&lt;/code&gt; myself.&lt;/p&gt;

</description>
      <category>linux</category>
      <category>c</category>
      <category>tooling</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
