RFC: file-like interface for Zope File and Image

Bug #143509 reported by TinoW
2
Affects Status Importance Assigned to Milestone
Zope 2
Invalid
Wishlist
TinoW

Bug Description

I'd like to implement an open() method for Zopes Image and File object
such that it is usable much like standard python file objects.

This should solve the following problems:

- efficient access in python scripts w/o the need of loading
  the whole data into a string using a non intuitive str(fileobject)
  (which even fails with Image objects, where you need to hack
  into the data structures)

- clean interface to classes deriving from these objects or
  using them (e.g Foto products etc)

I propose the following interface:

handle=fileobject.open(mode="r")

while it should default to "r" for text/* files
and "rb" for any other mime types.

handle.seek(offset,[whence])
handle.read([size])
 should we make size a sensible default here?

handle.write(), handle.truncate(), handle.writeline, ... etc.

readblock()
File-Objects use a pdata structure which is 128K block, readblock
would just read to the end of the current block and sets cursor
to the next block if any.

handle.next()

now thats interesting - python handles this with readline()
all the time. I'd like to use readline() for text/*
files and for all others rather use readblock() so its
easy to write:

for block in handle:
    dosomething(block)

in a most efficient way instead of:

while True:
    block=handle.readblock()
    if not block:
        break
    dosomething(block)

or even worser with read(128*1024)

I'd implement write() as truncating the file
from that point and write new blocks as
the data grows unless someone objects.

Revision history for this message
TinoW (tino-wildenhain) wrote :

discussion leads to the idea of having a blockiterator
like (readblock,) readblocks, xreadblocks
which return an ilterable. instead of changing the
behavior of next() for binary files.

Revision history for this message
Andreas Jung (ajung) wrote :

Changes: submitter email, edited transcript, importance (medium => low)

Revision history for this message
Jens Vagelpohl (dataflake-deactivatedaccount-deactivatedaccount) wrote :

Tino has never provided the promised implementation, marking this one as incomplete.

Changed in zope2:
status: Confirmed → Incomplete
importance: Low → Wishlist
Revision history for this message
Colin Watson (cjwatson) wrote :

The zope2 project on Launchpad has been archived at the request of the Zope developers (see https://answers.launchpad.net/launchpad/+question/683589 and https://answers.launchpad.net/launchpad/+question/685285). If this bug is still relevant, please refile it at https://github.com/zopefoundation/zope2.

Changed in zope2:
status: Incomplete → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.