1.0.1 • Published 7 years ago

hamarc v1.0.1

Weekly downloads
1
License
Unlicense
Repository
-
Last release
7 years ago
This program is public domain and is used for parsing and making Hamster
archive. Can access in memory or with files.

The exported object is a function for an abstract constructor; the
"prototype" property of it is the base class for what follows. The other
properties exported are File and Memory, which are constructors.

The constructed object has properties (mainly on the prototype object):

._get(address,length)
  Read from the file into a buffer. Can be used with .enumerate() in order
  to read the data of the enumerated lumps.

.caseFold
  A boolean value, normally true. If true, causes the .get() method to
  perform a case-insensitive comparison.

.enumerate()
  Returns a generator, which yields objects with three properties each,
  one yield per lump. The properties are called "name", which is the name
  of the lump, "address", which is the start address of the lump in the
  file, and "length", which is the size of the lump. The order of yielding
  is the order of the lumps in the file.

.get(name,[start],[length])
  Retrieve the data of a lump as a Buffer instance, or null if the lump
  does not exist. The start and length is within the lump; the start is
  therefore normally zero.

.nameEncoding
  Can be "ascii", "binary", or "utf8"; controls the character encoding for
  lump names. The default is "ascii".

.put(name,data)
  Add a new lump. The name is a string and data is the buffer.

You cannot delete or alter any existing lumps nor should you use both
reading and writing for the same file at the same time. If you want to
write, you should start with an empty file, or use append mode (the Memory
constructor is automatically using append mode).

The File constructor takes a file descriptor as its argument, and reads
and writes the file.

The Memory constructor takes a Buffer instance as its argument (optional;
if not provided, creates an empty buffer), and reads the buffer. If you
write new lumps, then the property called _buf can access the data.

If you are subclassing it, you must define _get(address,length) and
_put(buf) methods on the prototype for the subclass.

The format of a Hamster archive is zero or more "lumps" concatenated
together. Each lump consists of a null-terminated name, followed by the
32-bit data size in PDP byte order, followed by the data.