Crystar::Writer
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
Constants
Use long-link files if Name or Linkname exceeds the field size.
Constructors
Class methods
Instance methods
Adds an entry that will have its data copied from the given file. file is automatically closed after data is copied from it.
Close closes the tar archive by flushing the padding, and writing the footer. If the current file (from a prior call to WriteHeader) is not fully written, then this returns an error.
write writes to the current file in the tar archive. write returns the error ErrWriteTooLong if more than Header#size bytes are written after WriteHeader.
Calling write on special types like LINK, SYMLINK, CHAR, BLOCK, DIR, and FIFO returns (0, ErrWriteTooLong) regardless of what the Header#size claims.
write_header writes hdr and prepares to accept the file's contents. The Header#size determines how many bytes can be written for the next file. If the current file is not fully written, then this returns an error. This implicitly flushes any padding necessary before writing the header.