Hello, I use this code to create a .zip with a list of files:
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile));
for (int i=0;i<srcFiles.length;i++){
String fileName=srcFiles[i].getName();
ZipEntry zipEntry = new ZipEntry(fileName);
zos.putNextEntry(zipEntry);
InputStream fis = new FileInputStream(srcFiles[i]);
int read;
for(byte[] buffer=new byte[1024];(read=fis.read(buffer))>0;){
zos.write(buffer,0,read);
}
fis.close();
zos.closeEntry();
}
zos.close();
I don't know how the zip algorithm and the ZipOutputStream works, if it writes something before I read and send to 'zos' all of the data, the result file can be different in size of bytes than if I choose another buffer size.
in other words I don't know if the algorithm is like:
READ DATA-->PROCESS DATA-->CREATE .ZIP
or
READ CHUNK OF DATA-->PROCESS CHUNK OF DATA-->WRITE CHUNK IN .ZIP-->| ^-----------------------------------------------------------------------------------------------------------------------------
If this is the case, what buffer size is the best?
Update:
I have tested this code, changing the buffer size from 1024 to 64, and zipping the same files: with 1024 bytes the 80 KB result file was 3 bytes smaller than with 64 bytes buffer. Which is the best buffer size to produce the smallest .zip in the fatest time?