Esempio n. 1
0
 def test_uncompress_exact_len_err(self):
     data = six.binary_type(bytearray(range(100)))
     zipped = zlib.compress(data)
     total = len(zipped)
     reader = ExactSizeReader(ZipCompressedReader(six.BytesIO(zipped)))
     with self.assertRaises(EOFError):
         reader.read(size=total + 1)
Esempio n. 2
0
    def test_uncompress(self):
        byte_list = [random.randint(0, 255) for i in range(10000)]
        data = six.binary_type(bytearray(byte_list))
        zipped = zlib.compress(data)
        total = len(zipped)
        num_of_chunk = 20
        chunk_size = total // num_of_chunk
        in_buffer = six.BytesIO(zipped)
        reader = ZipCompressedReader(in_buffer)
        buff = six.BytesIO()
        for i in range(num_of_chunk):
            buff.write(reader.read(chunk_size))
            self.assertEqual(buff.getvalue(), data[:(i + 1) * chunk_size])

        buff.write(reader.read())
        self.assertEqual(buff.getvalue(), data)
        self.assertEqual(reader.read(), b"")
    def __init__(self, wxf_input):
        """WXF parser returning Python object from a WXF encoded byte sequence.
        """
        self.context = SerializationContext()
        self.reader = wxf_input_to_buffer(wxf_input)

        version, compress = self.parse_header()
        if compress == True:
            self.reader = ZipCompressedReader(self.reader)
        else:
            self.reader = ExactSizeReader(self.reader)
Esempio n. 4
0
 def __init__(self, wxf_input):
     """WXF parser returning Python object from a WXF encoded byte sequence.
     """
     self.context = SerializationContext()
     if isinstance(wxf_input, (six.binary_type, six.buffer_types)):
         self.reader = six.BytesIO(wxf_input)
     elif hasattr(wxf_input, 'read'):
         self.reader = wxf_input
     else:
         raise TypeError(
             'Class %s neither implements a read method nor is a binary type.'
             % wxf_input.__class__.__name__)
     version, compress = self.parse_header()
     if compress == True:
         self.reader = ZipCompressedReader(self.reader)
     else:
         self.reader = ExactSizeReader(self.reader)