-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Various polishing (mostly with pack)
* update documentation to note a confusion with get_file_offset vs. offset parameter in read_file * add extensive test case for the basic functionality of pack * fixed a bug in pack::add_memory discovered by the aformentioned test * label the pack method arguments in Angelscript registration * test runner now aborts when run from compiled, testts should be run from source for now * update readme to include example paths for extracting windev, new contributor guideline about API changes
- Loading branch information
Showing
6 changed files
with
74 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 9 additions & 3 deletions
12
doc/src/references/builtin/Data Manipulation/Classes/pack/methods/read_file.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
# read_file | ||
Get the contents of a file contained in a pack. | ||
|
||
`string pack::read_file(string pack_filename, uint offset, uint size);` | ||
`string pack::read_file(string pack_filename, uint offset_in_file, uint size);` | ||
|
||
## Arguments: | ||
* string pack_filename: the name of the file to be read. | ||
* uint offset: the file's offset in the pack (see `pack::get_file_offset`). | ||
* uint size: the size of the file (see `pack::get_file_size`). | ||
* uint offset: the offset within the file to begin reading data from (do not confuse this with pack::get_file_offset) | ||
* uint size: the number of bytes to read (see `pack::get_file_size` to read the entire file). | ||
|
||
## Returns: | ||
string: the contents of the file. | ||
|
||
## Remarks: | ||
This function allows you to read chunks of data from a file, as well as an entire file in one call. To facilitate this, the offset and size parameters are provided. offset is relative to the file being read E. 0 for the beginning of it. So to read a file in one chunk, you could execute: | ||
``` | ||
string file_contents = my_pack.read_file("filename", 0, my_pack.get_file_size("filename")); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "file_contents.nvgt" | ||
|
||
void test_pack() { | ||
put_file_contents("tmp/pack.dat", "test overwrite: lets start with bogus data"); | ||
dictionary cases; | ||
pack p; | ||
assert(p.open("tmp/pack.dat", PACK_OPEN_MODE_CREATE)); | ||
string[]@ case_list = find_files("case/*.nvgt"); | ||
for (uint i = 0; i < case_list.length(); i++) { | ||
string case_data = get_file_contents("case/" + case_list[i]); | ||
if (case_data.empty()) { | ||
case_list.remove_at(i); | ||
i--; | ||
continue; | ||
} | ||
assert(p.add_file("case/" + case_list[i], case_list[i])); | ||
assert(!case_data.empty()); | ||
assert(p.add_memory("mem/" + case_list[i], case_data)); | ||
cases.set(case_list[i], case_data); | ||
} | ||
p.close(); | ||
assert(p.open("tmp/pack.dat", PACK_OPEN_MODE_READ)); | ||
assert(p.size == cases.get_size() * 2); | ||
@case_list = p.list_files(); | ||
assert(case_list.length() == p.size); | ||
for (uint i = 0; i < case_list.length(); i++) { | ||
int size = p.get_file_size(case_list[i]); | ||
string pack_content = p.read_file(case_list[i], 0, size); | ||
string case_name = case_list[i]; | ||
if (case_name.starts_with("mem/")) case_name.erase(0, 4); | ||
string disc_content; | ||
assert(cases.get(case_name, disc_content)); | ||
assert(!disc_content.empty() and !pack_content.empty()); | ||
assert(disc_content == pack_content); | ||
} | ||
p.close(); | ||
file_delete("tmp/pack.dat"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters