Failure while executing KTar::open while using KCompressionDevice as the device

David Faure faure at kde.org
Sat Nov 28 14:35:52 UTC 2015


On Monday 23 November 2015 12:54:01 Luiz Romário Santana Rios wrote:
>  QNetworkReply is a sequential device.

Yes, that's the problem.

> This, as I
> understand it, is only a problem because KCompressionDevice is able to
> open any file it wants in any sequence

No, not KCompressionDevice, but KTar.
Remove compression from the equation to simplify reasoning, think about
a foo.tar download. Each file in the KTar object (after openArchive) can provide
a "limited io device" which allows the app to read from byte N to byte M in the .tar.
This kind of API is just fully incompatible with a sequential underlying device.

KCompressionDevice sits between KTar and the underlying device,
and looks at the compressed tar file as one file (remember, .tar.gz is one
compressed .tar file, not a tar of compressed files). Due to the way
zlib/bzip2 works it has to restart from zero if you seek backwards, so 
it introduces a performance issue, but it's not the one making this fully
impossible. The KArchiveFile api is the "issue", if the underlying device
is sequential.

> after all, tars are
> serializable, which means there's no need to seek back to extract a
> stream of data. 

Wrong, when providing a flexible API like "now read this file"
(as you would do when opening files in folders, nothing forces you
to read them in a specific order).

> Knowing that, I can think of two solutions:  [...]

kcompressiondevice isn't where the main problem is. The two solutions are:

1) document that KArchive does not work with sequential devices, i.e. force
the app to put the result into a QBuffer or temp file
2) handle sequential devices automatically within KArchive by creating a 
QBuffer or tempfile automatically.

Option 2 is nicer to app developers, but makes KArchive a bit too complex to my
taste. Plus, one could argue that app developers are in a better position to decide
whether a QBuffer is OK (reasonable size) or a temp file is necessary (huge files) ?

-- 
David Faure, faure at kde.org, http://www.davidfaure.fr
Working on KDE Frameworks 5



More information about the Kde-frameworks-devel mailing list