From c0a6e1c3a795abed98f7fb1111f5680cab43408e Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Wed, 16 Jan 2013 14:54:37 +0100 Subject: [PATCH] Finishing first usable prototype for an Issue #8 --- lib/core/dump.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/core/dump.py b/lib/core/dump.py index 3ca145a3b..aedb3e9f4 100644 --- a/lib/core/dump.py +++ b/lib/core/dump.py @@ -479,12 +479,16 @@ class Dump(object): blank = " " * (maxlength - len(value)) self._write("| %s%s" % (value, blank), newline=False, console=console) - #if len(value) > 10 and r'\x' in value: - # mimetype = magic.from_buffer(value, mime=True) - # if mimetype.startswith("application") or mimetype.startswith("image"): - # with codecs.open("%s%s%s" % (dumpDbPath, os.sep, "%s-%d.bin" % (column, randomInt(8))), "wb", UNICODE_ENCODING) as f: - # _ = safechardecode(value, True) - # f.write(_) + if len(value) > 10 and r'\x' in value: + mimetype = magic.from_buffer(value, mime=True) + if any(mimetype.startswith(_) for _ in ("application", "image")): + filepath = os.path.join(dumpDbPath, "%s-%d.bin" % (column, randomInt(8))) + warnMsg = "writing binary ('%s') content to file '%s' " % (mimetype, filepath) + logger.warn(warnMsg) + + with open(filepath, "wb") as f: + _ = safechardecode(value, True) + f.write(_) if conf.dumpFormat == DUMP_FORMAT.CSV: if field == fields: