Difference between revisions of "TruxtonFileIO"

From truxwiki.com
Jump to navigation Jump to search
(Created page with "This class provides read-only access to a file's contents in Truxton. From [https://docs.python.org/3/library/io.html#io.IOBase IOBase] it implements: * [https://docs.python...")
 
Line 6: Line 6:
 
* [https://docs.python.org/3/library/io.html#io.IOBase.closed closed]
 
* [https://docs.python.org/3/library/io.html#io.IOBase.closed closed]
 
* [https://docs.python.org/3/library/io.html#io.IOBase.fileno fileno()]
 
* [https://docs.python.org/3/library/io.html#io.IOBase.fileno fileno()]
* [https://docs.python.org/3/library/io.html#io.IOBase.flush flush()]
+
* [https://docs.python.org/3/library/io.html#io.IOBase.flush flush()] - Does nothing
 
* [https://docs.python.org/3/library/io.html#io.IOBase.isatty isatty()]
 
* [https://docs.python.org/3/library/io.html#io.IOBase.isatty isatty()]
 
* [https://docs.python.org/3/library/io.html#io.IOBase.readable readable()]
 
* [https://docs.python.org/3/library/io.html#io.IOBase.readable readable()]
Line 14: Line 14:
 
* [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()] - Does nothing
* [https://docs.python.org/3/library/io.html#io.IOBase.writable writable()]
+
* [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()]
+
* [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]
  
 
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:

Revision as of 13:57, 25 May 2020

This class provides read-only access to a file's contents in Truxton.

From IOBase it implements:

From RawIOBase it implements:

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.


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()