diff --git a/src/inputstream.py b/src/inputstream.py
index <HASH>..<HASH> 100644
--- a/src/inputstream.py
+++ b/src/inputstream.py
@@ -40,6 +40,8 @@ class HTMLInputStream(object):
         #Number of bytes to use when looking for a meta element with
         #encoding information
         self.numBytesMeta = 512
+        #Number of bytes to use when using detecting encoding using chardet
+        self.numBytesChardet = 100
         #Encoding to use if no other information can be found
         self.defaultEncoding = "windows-1252"
         
@@ -84,10 +86,18 @@ class HTMLInputStream(object):
         #Guess with chardet, if avaliable
         if encoding is None and chardet:
             try:
-                import chardet
-                buffer = self.rawStream.read()
-                encoding = chardet.detect(buffer)['encoding']
-                self.seek(buffer, 0)
+                from chardet.universaldetector import UniversalDetector
+                buffers = []
+                detector = UniversalDetector()
+                while not detector.done:
+                    buffer = self.rawStream.read(self.numBytesChardet)
+                    if not buffer:
+                        break
+                    buffers.append(buffer)
+                    detector.feed(buffer)
+                detector.close()
+                encoding = detector.result['encoding']
+                self.seek("".join(buffers), 0)
             except ImportError:
                 pass
         # If all else fails use the default encoding
Avoid reading the whole input when using chardet (by reading chunks of bytes and feeding them to the chardet UniversalDetector until it detects the encoding with enough confidence)

--HG--
extra : convert_revision : svn%3Aacbfec<I>-<I>-<I>-a<I>-<I>a<I>e<I>e0/trunk%<I>