ngdb.reader
Class for handling the low-level reading of a Norton Guide database.
GuideReader
GuideReader(guide)
Low-level guide reading class.
Note
For now, no optimisation has taken place, in many cases the way this class reads data from a guide will be a method that's on the slower side. This is on purpose; it's about readable code that represents the underlying data structure rather than the fastest method of getting data into memory.
Once the rest of the library is done and working well this extra bit if docstring will likely be removed because work to improve the speed of this class will finally take place.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
Path
|
The guide to open. |
required |
RLE_MARKER
class-attribute
instance-attribute
RLE_MARKER = chr(255)
The value that marks run-length-encoded spaces.
closed
property
closed
Is the file closed?
pos
property
pos
The current position within the file.
close
close()
Close the guide.
goto
goto(pos)
peek_word
peek_word(decrypt=True)
read_byte
read_byte(decrypt=True)
read_long
read_long(decrypt=True)
read_offset
read_offset()
Read an offset value from the guide.
Returns:
Type | Description |
---|---|
int
|
The offset value read. |
Note
This function ensures that an offset value that means 'there is
no offset' returns as -1
.
read_str
read_strz
Read a nul-terminated string from the guide.
This is similar to read_str
,
but it will read only as far as the first nul
it encounters,
within the bounds of length
, and the file read location will be
correctly settled to take this into account.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
int
|
The maximum length of the string to read. |
required |
|
bool
|
Should the string be decrypted? |
True
|
Returns:
Type | Description |
---|---|
str
|
The string value read. |
read_word
read_word(decrypt=True)
skip
skip(count=1)
unrle
classmethod
unrle(rle_text)
Un-run-length-encode the given string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str
|
The text that needs expanding. |
required |
Returns:
Type | Description |
---|---|
str
|
The given text with all RLE components expanded. |
Note
Norton Guide database files use a very simple form of
run-length-encoding for spaces. Simply put, if you find a byte
in a string that is 0xFF
, then the next byte is the number of
spaces to insert into the string at this point. I've also found
that 0xFF
followed by 0xFF
seems to mean you should insert a
literal 0xFF
(I think), although I've found that using a
literal space makes more sense.