mercredi 16 septembre 2015

Open a sqlite3 database from an io.BytesIO stream?

In Python3.4, is it possible to open an SQLite3 database from an io.BytesIO stream?

Something akin to:

with open("temp.db", "rb") as openf
    byte_stream = io.BytesIO(openf.read())
sqlite3.connect(byte_stream)

The short story is: I have a stream (byte_stream) that is the sqlite database file. I can't do the following for security reasons (can't create an unencrypted file):

with open("temp.db", "wb") as openf:
    openf.write(byte_stream)
sqlite3.connect("temp.db")

Is there some lower-level API for sqlite3 that I haven't been able to find? I assume that sqlite3.connect simply calls open() at some point and opens the file as a byte stream anyway. I'm simply trying to skip that open() step.

Aucun commentaire:

Enregistrer un commentaire