class Crystar::Writer

Overview

Writer provides sequential writing of a tar archive. Writer#write_header begins a new file with the provided Header, and then Writer can be treated as an io.Writer to supply that file's data via invoking Writer#write method .

Example

require "tar"

File.open("./file.tar", "w") do |file|
  Crystar::Writer.open(file) do |tar|
    # add file to archive
    tar.add File.open("./some_file.txt")
    # Manually create the Header with info per your choice
    hdr = Header.new(
      name: "Your file Name",
      size: 100_i64,  # Contents size
      mode: 0o644_i64 # Permission and mode bits
    # ..... Look into `Crystar::Header`
    )
    tar.write_header hdr
    tar.write "your file contents".to_slice

    # Create header from File you have already opened.
    hdr = file_info_header(file, file.path)
    tar.write_header hdr
    tar.write file.gets_to_end.to_slice
  end
end

Defined in:

lib/crystar/src/tar/writer.cr
ext/crystar/writer.cr

Instance Method Summary

Instance methods inherited from class Object

or(other : T) : T | self forall T or, pipe(&) pipe

Instance Method Detail

def curr : Crystar::Writer::FileWriter #

[View source]