Skip to content

Instantly share code, notes, and snippets.

@evansd
Created October 21, 2014 15:22
Show Gist options
  • Select an option

  • Save evansd/17f119eeec70d4451ac2 to your computer and use it in GitHub Desktop.

Select an option

Save evansd/17f119eeec70d4451ac2 to your computer and use it in GitHub Desktop.
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