Skip to content

Commit

Permalink
Upgrade File.getBytes to have starting position and length.
Browse files Browse the repository at this point in the history
This adds the ability to construct a `haxe.io.Bytes` out of part of the file's bytes in the most efficient way possible.
  • Loading branch information
SomeGuyWhoLovesCoding authored Sep 9, 2024
1 parent 5fe6742 commit fd8e3bf
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions std/sys/io/File.hx
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ extern class File {
/**
Retrieves the binary content of the file specified by `path`.
The stream starts at `pos` and ends at `len`. (If `len` exceeds the size of the file, the stream should stop.)
If the file does not exist or can not be read, an exception is thrown.
`sys.FileSystem.exists` can be used to check for existence.
If `path` is null, the result is unspecified.
**/
static function getBytes(path:String):haxe.io.Bytes;
static function getBytes(path:String, pos:Int = 0, len:Int = 0):haxe.io.Bytes;

/**
Stores `bytes` in the file specified by `path` in binary mode.
Expand All @@ -69,7 +71,7 @@ extern class File {
static function saveBytes(path:String, bytes:haxe.io.Bytes):Void;

/**
Returns an `FileInput` handle to the file specified by `path`.
Returns a `FileInput` handle to the file specified by `path`.
If `binary` is true, the file is opened in binary mode. Otherwise it is
opened in non-binary mode.
Expand All @@ -86,7 +88,7 @@ extern class File {
static function read(path:String, binary:Bool = true):FileInput;

/**
Returns an `FileOutput` handle to the file specified by `path`.
Returns a `FileOutput` handle to the file specified by `path`.
If `binary` is true, the file is opened in binary mode. Otherwise it is
opened in non-binary mode.
Expand Down

0 comments on commit fd8e3bf

Please sign in to comment.