How do I specify the compression level to gzip?

조회 수: 4 (최근 30일)
sunil anandatheertha
sunil anandatheertha 2011년 7월 19일
댓글: raym 2018년 4월 19일
Is there a way I can specify the zip compression to "best compression" or "normal compression".

답변 (3개)

Jan
Jan 2011년 7월 19일
This is the core method:
function zipLevel(ZIPFile, FileList, Level)
import java.io.*
import java.util.zip.*
import com.mathworks.mlwidgets.io.InterruptibleStreamCopier.*
if nargin < 3, Level = 6; end
% Create output stream and set the level of compression:
try
fileOut = FileOutputStream(ZIPFile);
catch
error(['*** ', mfilename, ': Cannot open for output: ', ...
char(10), ' ', ZIPFile]);
end
zipOut = ZipOutputStream(fileOut);
zipOut.setLevel(Level);
% This InterruptibleStreamCopier is unsupported and
% may change without notice.
StreamCopier = getInterruptibleStreamCopier;
% Append files to zip file:
FileList = cellstr(FileList);
for iFile = 1:numel(FileList)
aFile = FileList{iFile};
fileIn = FileInputStream(aFile);
zipObj = ZipEntry(aFile);
zipOut.putNextEntry(zipObj);
StreamCopier.copyStream(fileIn, zipOut);
fileIn.close;
zipOut.closeEntry;
end
zipOut.close;
fileOut.close;
This should be expanded by checking the the existence of file, getting the contents of folders and using a root folder for relative file names. Comments and file times can also be included by this method.
  댓글 수: 1
raym
raym 2018년 4월 19일
Hi, I run your code and found that the filelist not compressed into the ZIPFile. instead, when I double click the zip file, it directly opens the D drive, and all the hard drive was indexed from here. But the file size is only 140kb.

댓글을 달려면 로그인하십시오.


the cyclist
the cyclist 2011년 7월 19일
I don't know how to do this, but if you type
>> edit zip
you will get a bit more into the innards of the creation of the Java ZipEntry object, so maybe that will help.

Friedrich
Friedrich 2011년 7월 19일
Hi,
sry no you can't. At least without modifying the MATLAB Java code.

카테고리

Help CenterFile Exchange에서 Instrument Control Toolbox Supported Hardware에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by