← Back to team overview

beeseek-devs team mailing list archive

[Branch ~beeseek-devs/beeseek/trunk] Rev 202: Add GzipDecoder class to decode gzip data.

 

------------------------------------------------------------
revno: 202
committer: Andrea Corbellini <andrea.corbellini@xxxxxxxxxxx>
branch nick: trunk
timestamp: Tue 2009-01-20 20:14:00 +0100
message:
  Add GzipDecoder class to decode gzip data.
  Developers are now able to decompress gzipped data using an 
  IStreamDecoder object.
added:
  beeseek/decoders/gzip.py
modified:
  beeseek/decoders/__init__.py
  beeseek/decoders/base.py
    ------------------------------------------------------------
    revno: 200.1.9
    committer: Andrea Corbellini <andrea.corbellini@xxxxxxxxxxx>
    branch nick: decoders
    timestamp: Tue 2009-01-20 20:12:58 +0100
    message:
      Add GzipDecoder.
    added:
      beeseek/decoders/gzip.py
    modified:
      beeseek/decoders/__init__.py
    ------------------------------------------------------------
    revno: 200.1.8
    committer: Andrea Corbellini <andrea.corbellini@xxxxxxxxxxx>
    branch nick: decoders
    timestamp: Tue 2009-01-20 20:12:44 +0100
    message:
      Add NullStreamDecoder.
    modified:
      beeseek/decoders/base.py

=== modified file 'beeseek/decoders/__init__.py'
--- a/beeseek/decoders/__init__.py	2009-01-19 19:38:06 +0000
+++ b/beeseek/decoders/__init__.py	2009-01-20 19:12:58 +0000
@@ -16,4 +16,5 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 from beeseek.decoders.base import *
+from beeseek.decoders.gzip import *
 from beeseek.decoders.chunks import *

=== modified file 'beeseek/decoders/base.py'
--- a/beeseek/decoders/base.py	2009-01-19 19:38:19 +0000
+++ b/beeseek/decoders/base.py	2009-01-20 19:12:44 +0000
@@ -71,6 +71,14 @@
         pass
 
 
+class NullStreamDecoder(object):
+
+    implements(IStreamDecoder)
+
+    def decode(self, data):
+        return data
+
+
 class NullSocketDecoder(object):
 
     implements(ISocketDecoder)

=== added file 'beeseek/decoders/gzip.py'
--- a/beeseek/decoders/gzip.py	1970-01-01 00:00:00 +0000
+++ b/beeseek/decoders/gzip.py	2009-01-20 19:12:58 +0000
@@ -0,0 +1,44 @@
+#coding=UTF-8
+
+# Copyright (C) 2007-2009  BeeSeek Developers
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+import zlib
+from beeseek.interfaces import implements
+from beeseek.decoders import IStreamDecoder
+
+__all__ = ('GzipDecoder',)
+
+
+class GzipDecoder(object):
+
+    __slots__ = '_decompress', '_header'
+    implements(IStreamDecoder)
+
+    def __init__(self):
+        self._decompress = None
+        self._header = 10
+
+    def decode(self, buf):
+        if not self._decompress:
+            header = self._header
+            read = header - len(buf)
+            if read >= 0:
+                self._header = read
+                return ''
+            else:
+                buf = buf[header:]
+            self._decompress = zlib.decompressobj().decompress
+        return self._decompress(buf)



--
BeeSeek mainline
https://code.launchpad.net/~beeseek-devs/beeseek/trunk

You are receiving this branch notification because you are subscribed to it.