About KArchive::data()

David Faure faure at kde.org
Mon Nov 5 23:07:50 GMT 2007


On Monday 05 November 2007, Szombathelyi György wrote:
> Hello,
> 
> I've got some problem about KArchive::data() method:
> If the file is rather large, this method tries to return the whole file in one 
> QByteArray. That could easily fill all the available memory, trash the disk 
> till the system runs out of swap space. 
Yes, it is documented to be so. The recommended way to read a file from an archive
is to use createDevice() and read from that device - no data copying, and no huge memory
allocation.

> I suggest changing it to "QByteArray  
> KArchive::data(qint64 size)", where size means the chunk size which should be 
> returned. The caller should call data(size) till the returned 
> QByteArray.isEmpty().
This is bad API since it's state-based IMHO. And after all the QIODevice API has all we
need for reading chunks already.

-- 
David Faure, faure at kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).




More information about the kde-core-devel mailing list