How to use the rhash.hash_for_file function in RHash

To help you get started, we’ve selected a few RHash examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rhash / RHash / bindings / python / test_rhash.py View on Github external
def test_update_file(self):
        """Test the update_file() method"""
        path = 'python_test_input_123.txt'
        file = open(path, 'wb')
        file.write(b"\0\1\2\n")
        file.close()

        ctx = rhash.RHash(rhash.SHA1)
        ctx.update_file(path).finish()
        self.assertEqual('e3869ec477661fad6b9fc25914bb2eee5455b483', str(ctx))
        self.assertEqual(
            'e3869ec477661fad6b9fc25914bb2eee5455b483',
            rhash.hash_for_file(path, rhash.SHA1))
        self.assertEqual(
            'magnet:?xl=4&dn=python_test_input_123.txt&xt=urn:tree:tiger:c6docz63fpef5pdfpz35z7mw2iozshxlpr4erza',
            rhash.magnet_for_file(path, rhash.TTH))
        os.remove(path)