CRAM.Block (cram v0.1.0)

Copy Markdown View Source

One CRAM block header and its compressed payload (CRAMv3 §8).

The payload is the on-disk compressed bytes. This struct does not hold an inflated copy. raw_size is the declared uncompressed size.

Summary

Types

t()

One block.

Functions

Name for a content-type byte.

True when byte is a method this library can name.

Name for a compression method byte.

Types

t()

@type t() :: %CRAM.Block{
  compressed_size: non_neg_integer(),
  content_id: integer(),
  content_type: non_neg_integer(),
  content_type_name: atom(),
  crc32: non_neg_integer(),
  crc32_ok: boolean(),
  data: binary(),
  method: non_neg_integer(),
  method_name: atom(),
  offset: non_neg_integer(),
  raw_size: non_neg_integer(),
  slice: CRAM.SliceHeader.t() | nil
}

One block.

  • :offset — byte offset of the block header

  • :method — compression method byte

  • :method_name — :raw, :gzip, :bzip2, :lzma, :rans4x8, :rans4x16, :adaptive_arithmetic, :fqzcomp, :name_tokenizer, or :unknown

  • :content_type — content-type byte

  • :content_type_name — :file_header, :compression_header, :slice_header, :external_data, :core_data, or :unknown

  • :content_id — block content id

  • :compressed_size — payload size on disk

  • :raw_size — declared uncompressed size

  • :crc32 — stored CRC32

  • :crc32_ok — whether the stored CRC matches the payload

  • :data — compressed payload

  • :slice — parsed slice header, or nil when this block is not one

    iex> %CRAM.Block{method: 1, method_name: :gzip, content_type: 0, content_type_name: :file_header, content_id: 0, compressed_size: 0, raw_size: 0, crc32: 0, crc32_ok: true, data: <<>>, offset: 0}.method_name :gzip

Functions

content_type_name(byte)

@spec content_type_name(non_neg_integer()) :: atom()

Name for a content-type byte.

byte is an integer. Known values are 0, 1, 2, 4, and 5. There is no type

  1. Any other integer is :unknown. Does not raise.

    iex> CRAM.Block.content_type_name(0) :file_header iex> CRAM.Block.content_type_name(3) :unknown

known_method?(byte)

@spec known_method?(non_neg_integer()) :: boolean()

True when byte is a method this library can name.

False for any other integer, including a negative one. Does not raise.

iex> CRAM.Block.known_method?(0)
true
iex> CRAM.Block.known_method?(99)
false

method_name(byte)

@spec method_name(non_neg_integer()) :: atom()

Name for a compression method byte.

byte is an integer. Bytes 0 through 8 use the names in the type docs. Any other integer is :unknown. Does not raise.

iex> CRAM.Block.method_name(1)
:gzip
iex> CRAM.Block.method_name(99)
:unknown