Xgit v0.2.0 Xgit.Util.TrailingHashDevice View Source
Creates an iodevice
process that supports git file formats with a trailing
SHA-1 hash.
When reading, the trailing 20 bytes are interpreted as a SHA-1 hash of the
remaining file contents and can be verified using the valid_hash?/1
function.
This is an admittedly minimal implementation; just enough is implemented to allow Xgit's index file parser to do its work.
Link to this section Summary
Functions
Returns a specification to start this module under a supervisor.
Creates an IO device that reads a file with trailing hash.
Creates an IO device that writes to a file with trailing hash.
Creates an IO device that reads a string with trailing hash.
Returns true
if this is process is an TrailingHashDevice
instance.
Returns true
if the hash at the end of the file matches the hash
generated while reading the file.
Link to this section Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
open_file(path)
View Sourceopen_file(path :: Path.t()) :: {:ok, pid()} | {:error, File.posix()}
Creates an IO device that reads a file with trailing hash.
Unlike File.open/2
and File.open/3
, no options or function are
accepted.
This device can be passed to IO.binread/2
.
Return Value
{:ok, pid}
where pid
points to an IO device process.
{:ok, reason}
if the file could not be opened. See File.open/2
for
possible values for reason
.
open_file_for_write(path, opts \\ [])
View Sourceopen_file_for_write(path :: Path.t(), opts :: Keyword.t()) :: {:ok, pid()} | {:error, File.posix()}
Creates an IO device that writes to a file with trailing hash.
Unlike File.open/2
and File.open/3
, no options or function are
accepted.
This device can be passed to IO.binwrite/2
.
Options
:max_file_size
(non-negative integer) may be passed, which will cause a
failure after the _n_th byte is written. This is intended for internal
testing purposes.
Return Value
{:ok, pid}
where pid
points to an IO device process.
{:ok, reason}
if the file could not be opened. See File.open/2
for
possible values for reason
.
Creates an IO device that reads a string with trailing hash.
This is intended mostly for internal testing purposes.
Unlike StringIO.open/2
and StringIO.open/3
, no options or function are
accepted.
This device can be passed to IO.binread/2
.
Return Value
{:ok, pid}
where pid
points to an IO device process.
Returns true
if this is process is an TrailingHashDevice
instance.
Note the difference between this function and valid_hash?/1
.
Returns true
if the hash at the end of the file matches the hash
generated while reading the file.
Should only be called once and only once when the entire file (sans SHA-1 hash) has been read.
Return Values
true
or false
if the SHA-1 hash was found and was valid (or not).
:too_soon
if called before the SHA-1 hash is expected.
:already_called
if called a second (or successive) time.
:opened_for_write
if called on a device that was opened for write.