Created
October 21, 2014 15:22
-
-
Save evansd/17f119eeec70d4451ac2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import hashlib | |
| import json | |
| class HashWrapper(object): | |
| """ | |
| Wraps a hashlib object to make it file-like (i.e. give it a `write` method) | |
| """ | |
| def __init__(self, hashobj=None): | |
| self.hashobj = hashlib.sha1() if not hashobj else hashobj | |
| self.write = hashobj.update | |
| def add(self, item): | |
| json.dump(item, self, sort_keys=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment