Difference between revisions of "TruxtonFileIO"
Jump to navigation
Jump to search
| Line 1: | Line 1: | ||
This class provides read-only access to a file's contents in Truxton. | This class provides read-only access to a file's contents in Truxton. | ||
| + | =IOBase Methods= | ||
From [https://docs.python.org/3/library/io.html#io.IOBase IOBase] it implements: | From [https://docs.python.org/3/library/io.html#io.IOBase IOBase] it implements: | ||
| Line 14: | Line 15: | ||
* [https://docs.python.org/3/library/io.html#io.IOBase.seekable seekable()] | * [https://docs.python.org/3/library/io.html#io.IOBase.seekable seekable()] | ||
* [https://docs.python.org/3/library/io.html#io.IOBase.tell tell()] | * [https://docs.python.org/3/library/io.html#io.IOBase.tell tell()] | ||
| − | * [https://docs.python.org/3/library/io.html#io.IOBase.truncate truncate()] - | + | * [https://docs.python.org/3/library/io.html#io.IOBase.truncate truncate()] - - Always returns [https://docs.python.org/3.8/library/exceptions.html?highlight=ioerror#IOError IOError] |
* [https://docs.python.org/3/library/io.html#io.IOBase.writable writable()] - Always returns [https://docs.python.org/3.8/library/constants.html#False False] | * [https://docs.python.org/3/library/io.html#io.IOBase.writable writable()] - Always returns [https://docs.python.org/3.8/library/constants.html#False False] | ||
* [https://docs.python.org/3/library/io.html#io.IOBase.writelines writelines()] - Always returns [https://docs.python.org/3.8/library/exceptions.html?highlight=ioerror#IOError IOError] | * [https://docs.python.org/3/library/io.html#io.IOBase.writelines writelines()] - Always returns [https://docs.python.org/3.8/library/exceptions.html?highlight=ioerror#IOError IOError] | ||
| + | =RawIOBase= | ||
From [https://docs.python.org/3/library/io.html#io.RawIOBase RawIOBase] it implements: | From [https://docs.python.org/3/library/io.html#io.RawIOBase RawIOBase] it implements: | ||
| Line 23: | Line 25: | ||
* [https://docs.python.org/3/library/io.html#io.RawIOBase.readall readall()] | * [https://docs.python.org/3/library/io.html#io.RawIOBase.readall readall()] | ||
* [https://docs.python.org/3/library/io.html#io.RawIOBase.readinto readinto()] | * [https://docs.python.org/3/library/io.html#io.RawIOBase.readinto readinto()] | ||
| − | * [https://docs.python.org/3/library/io.html#io.RawIOBase.write write()] | + | * [https://docs.python.org/3/library/io.html#io.RawIOBase.write write()] - Always returns [https://docs.python.org/3.8/library/exceptions.html?highlight=ioerror#IOError IOError] |
| + | =Truxton Methods= | ||
The above methods will let you read from a file in Truxton as if it were any other file in Python. | The above methods will let you read from a file in Truxton as if it were any other file in Python. | ||
The following methods are also present to make tasks of adding items extracted from a file easier. | The following methods are also present to make tasks of adding items extracted from a file easier. | ||
| − | * [[TruxtonFileIO_newartifact | newartifact()]] | + | * [[TruxtonFileIO_newartifact | newartifact()]] - Creates a record in the [[Entity Table | entity table.]] |
| − | * [[TruxtonFileIO_newchild | newchild()]] | + | * [[TruxtonFileIO_newchild | newchild()]] - Creates a writable file that will be a child of this file. |
| − | * [[TruxtonFileIO_newevent | newevent()]] | + | * [[TruxtonFileIO_newevent | newevent()]] - |
* [[TruxtonFileIO_newexif | newexif()]] | * [[TruxtonFileIO_newexif | newexif()]] | ||
* [[TruxtonFileIO_newlocation | newlocation()]] | * [[TruxtonFileIO_newlocation | newlocation()]] | ||
Revision as of 14:03, 25 May 2020
This class provides read-only access to a file's contents in Truxton.
IOBase Methods
From IOBase it implements:
- close()
- closed
- fileno()
- flush() - Does nothing
- isatty()
- readable()
- readline()
- readlines()
- seek()
- seekable()
- tell()
- truncate() - - Always returns IOError
- writable() - Always returns False
- writelines() - Always returns IOError
RawIOBase
From RawIOBase it implements:
- read()
- readall()
- readinto()
- write() - Always returns IOError
Truxton Methods
The above methods will let you read from a file in Truxton as if it were any other file in Python. The following methods are also present to make tasks of adding items extracted from a file easier.
- newartifact() - Creates a record in the entity table.
- newchild() - Creates a writable file that will be a child of this file.
- newevent() -
- newexif()
- newlocation()
- newrelation()
- newurl()
- newusb()
Sample
This will retrieve a file from Truxton, print the name and hash as stored in the database then calculate a hash on the contents and print that.
import truxton
import hashlib
def main():
t = truxton.create()
file = t.getfileid("5ec2a123-74d6-5da7-0653-4e6800000000")
print(file.hash + " is the hash in the database for " + file.name )
bytes = file.readall()
readable_hash = hashlib.md5(bytes).hexdigest()
print(readable_hash + " is the calculated hash of the contents")
if __name__ == "__main__":
main()