From cce074e2730809aa1178135e1a0b2bdfba491611 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Mon, 25 Mar 1996 18:54:33 +0000 Subject: new binhex from Jack (much faster) --- Lib/binhex.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Lib/binhex.py b/Lib/binhex.py index 9e20d87..cdb961e 100644 --- a/Lib/binhex.py +++ b/Lib/binhex.py @@ -131,20 +131,26 @@ class _Hqxcoderengine: todo = (datalen/3)*3 data = self.data[:todo] self.data = self.data[todo:] + if not data: + return self.hqxdata = self.hqxdata + binascii.b2a_hqx(data) - while len(self.hqxdata) > self.linelen: - self.ofp.write(self.hqxdata[:self.linelen]+'\n') - self.hqxdata = self.hqxdata[self.linelen:] + self._flush(0) + + def _flush(self, force): + first = 0 + while first <= len(self.hqxdata)-self.linelen: + last = first + self.linelen + self.ofp.write(self.hqxdata[first:last]+'\n') self.linelen = LINELEN + first = last + self.hqxdata = self.hqxdata[first:] + if force: + self.ofp.write(self.hqxdata + ':\n') def close(self): if self.data: self.hqxdata = self.hqxdata + binascii.b2a_hqx(self.data) - while self.hqxdata: - self.ofp.write(self.hqxdata[:self.linelen]) - self.hqxdata = self.hqxdata[self.linelen:] - self.linelen = LINELEN - self.ofp.write(':\n') + self._flush(1) self.ofp.close() del self.ofp @@ -290,7 +296,6 @@ class _Hqxdecoderengine: while 1: try: decdatacur, self.eof = binascii.a2b_hqx(data) - if self.eof: print 'EOF' break except binascii.Incomplete: pass -- cgit v0.12