/// <summary> /// To be added. /// </summary> /// <param name="context"></param> /// <param name="fileDestinationPath"></param> public ZipFileBuilder(Context context, string fileDestinationPath) { Context = context; FilePath = fileDestinationPath; var fileStream = new System.IO.FileStream(FilePath, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite); ZipStream = new Java.Util.Zip.ZipOutputStream(fileStream); }
public void Zip(string[] files, string zipFilePath, string comment = null, int bufferSize = 1024, CancellationToken?token = null) { if (string.IsNullOrEmpty(zipFilePath)) { throw new ArgumentNullException(nameof(zipFilePath)); } if (token == null) { token = CancellationToken.None; } using (var fileOutputStream = File.Create(zipFilePath)) { using (var zipOutputStream = new Java.Util.Zip.ZipOutputStream(fileOutputStream)) { if (!string.IsNullOrEmpty(comment)) { zipOutputStream.SetComment(comment); } var buffer = new byte[bufferSize]; foreach (var file in files.Where(p => !string.IsNullOrEmpty(p))) { if (token.Value.IsCancellationRequested) { break; } using (var entry = new Java.Util.Zip.ZipEntry(Path.GetFileName(file))) { zipOutputStream.PutNextEntry(entry); using (var readStream = File.OpenRead(file)) { using (var bufferedStream = new BufferedStream(readStream)) { int count; while ((count = bufferedStream.Read(buffer, 0, bufferSize)) > 0) { zipOutputStream.Write(buffer, 0, count); } } } zipOutputStream.CloseEntry(); } } zipOutputStream.Close(); } } }
/// <summary> /// To be added. /// </summary> /// <param name="scanCompletedListener"></param> /// <exception cref="Java.Util.Zip.ZipException"/> /// <exception cref="Java.IO.IOException"/> public void Build(MediaScannerConnection.IOnScanCompletedListener scanCompletedListener) { ZipStream.Close(); ZipStream = null; MediaScannerConnection.ScanFile(Context, new string[] { FilePath }, new string[] { "application/zip" }, scanCompletedListener); }