class HRX::File

A file in an HRX archive.

Attributes

comment[R]

The comment that appeared before this file, or ‘nil` if it had no preceding comment.

HRX comments are always encoded as UTF-8.

This string is frozen.

content[R]

The contents of the file.

HRX file contents are always encoded as UTF-8.

This string is frozen.

path[R]

The path to this file, relative to the archive’s root.

HRX paths are always ‘/`-separated and always encoded as UTF-8.

This string is frozen.

Public Class Methods

new(path, content, comment: nil) click to toggle source

Creates a new file with the given path, content, and comment.

Throws an HRX::ParseError if ‘path` is invalid, or an EncodingError if any argument can’t be converted to UTF-8.

# File lib/hrx/file.rb, line 45
def initialize(path, content, comment: nil)
  @comment = comment&.clone&.encode("UTF-8")&.freeze
  @path = HRX::Util.scan_path(StringScanner.new(path.encode("UTF-8"))).freeze

  if @path.end_with?("/")
    raise HRX::ParseError.new("path \"#{path}\" may not end with \"/\"", 1, path.length - 1)
  end

  @content = content.clone.encode("UTF-8").freeze
end