python - Compress text to store in mysql database, does it have to be base64 -
python - Compress text to store in mysql database, does it have to be base64 -
i got code here defines compressed text field. need because i'm storing much text , database big. problem code doesn't have documentation , it's confusing.
particularly, have modified code little, in here:
def get_prep_value(self,value): if not value: homecoming value try: tmp = value.encode('utf-8').encode('bz2') except exception: homecoming value else: if len(tmp) > len(value): homecoming value homecoming tmp
in original code, encode base64 after bz2, shows not optimize wondering if there might reason that? btw. i'm using mysql back-end
i removed lines 11-15 didn't create sense me.. why decode in here?
base64-encoding info guarantees resulting info safe insert text-only column (while sacrificing of compression bzip2 offers). author must have had requirement insert info text column. if you're using blob type of column, don't need worry base64 part (and you'll more compression).
the linked illustration seems bit roundabout in lite of fact mysql supports gzip compression natively. see mysql documentation regarding compression , encryption functions, particularly compress()
, uncompress()
. if have blob columns can store binary data, these happily store compressed data.
the downside approach uncompressed info needs create trip server compressed (or uncompressed before shipping on network client). might have provided motivation behind author's original snippet.
python django compression
Comments
Post a Comment