bytesio

How the write(), read() and getvalue() methods of Python io.BytesIO work?

How the write(), read() and getvalue() methods of Python io.BytesIO work? Question: I’m trying to understand the write() and read() methods of io.BytesIO. My understanding was that I could use the io.BytesIO as I would use a File object. import io in_memory = io.BytesIO(b’hello’) print( in_memory.read() ) The above code will return b’hello’ as expected, …

Total answers: 3

Convert PDF page to image with pyPDF2 and BytesIO

Convert PDF page to image with pyPDF2 and BytesIO Question: I have a function that gets a page from a PDF file via pyPdf2 and should convert the first page to a png (or jpg) with Pillow (PIL Fork) from PyPDF2 import PdfFileWriter, PdfFileReader import os from PIL import Image import io # Open PDF …

Total answers: 2

Confusing about StringIO, cStringIO and ByteIO

Confusing about StringIO, cStringIO and ByteIO Question: I have googled and also search on SO for the difference between these buffer modules. However, I still don’t understand very well and I think some of the posts I read are out of date. In Python 2.7.11, I downloaded a binary file of a specific format using …

Total answers: 1

Writing then reading in-memory bytes (BytesIO) gives a blank result

Writing then reading in-memory bytes (BytesIO) gives a blank result Question: I wanted to try out the python BytesIO class. As an experiment I tried writing to a zip file in memory, and then reading the bytes back out of that zip file. So instead of passing in a file-object to gzip, I pass in …

Total answers: 3