owncloud/core — pull request #8390 by jknockaert (2014-04-28 20:56:43+00:00)
Title: make encryption stream wrapper seekable

I refactored the encryption stream wrapper to make it seekable. This is necessary to handle http range requests efficiently. With the old code the Sabre webdav server would set the beginning of the range by applying fseek on the unencrypted stream, which resulted in the pointer of the encrypted streem set in the middle of a block and subsequently an error in decrypting the subsequent part of the stream. After making the stream seekable (with fseek applying on the unencrypted rather than the encrypted string) the dav server can much more efficiently handle http get operations on parts of large files.

The general concept is to add a position variable as a pointer for the unencrypted stream. This pointer can be moved around. To read from the stream the current block is stored in cache. Writing is also done on the cache. If necessary, read and write spill over in the next block(s). When moving to another block the cash is always flushed (with a writeflag determining if write is necessary).

The getFileSize function is updated along (making use of the seekable nature of the stream).