SharpZipLib.Portable'u uygulamaya çalışırken buraya geldim. IVirtualFileSystem
olmadan kullanmaya başladım çünkü zaten (iOS
ve Android
üzerinde test edilmiş) dosya sisteminde okuma ve yazma işlemlerini bilen (PCLStorage) adlı bir kitaplık vardı.
NOT: Bu uygulamaları iOS
, Android
hedefleyen bir PCL içindeki tüm bulunmaktadır. Android veya iOS için özel bir kod gerekli değildir. Eğer SharpZipLib.Portable
sen (orijinal SharpZipLib) buradan okuyabilirsiniz nasıl kullanılacağına ilişkin bazı örnekler almak istiyorsanız
public async void DonwLoadAndStoreZipFile()
{
var bytes = await DownloadImageAsync("https://github.com/fluidicon.png");
// IFolder interface comes from PCLStorage
IFolder rootFolder = FileSystem.Current.LocalStorage;
IFolder folder = await rootFolder.CreateFolderAsync("zipFolder", CreationCollisionOption.OpenIfExists);
IFile file = await folder.CreateFileAsync("test.zip" , CreationCollisionOption.OpenIfExists);
using (Stream stream = await file.OpenAsync(FileAccess.ReadAndWrite))
{
await stream.WriteAsync(bytes, 0, bytes.Length);
using (var zf = new ZipFile(stream))
{
foreach (ZipEntry zipEntry in zf)
{
// Gete Entry Stream.
Stream zipEntryStream = zf.GetInputStream(zipEntry);
// Create the file in filesystem and copy entry stream to it.
IFile zipEntryFile = await rootFolder.CreateFileAsync(zipEntry.Name , CreationCollisionOption.FailIfExists);
using(Stream outPutFileStream = await zipEntryFile.OpenAsync(FileAccess.ReadAndWrite))
{
await zipEntryStream.CopyToAsync(outPutFileStream);
}
}
}
}
}
: Burada
PCLStorage
ve
SharpZipLib.Portable
kullanarak bir Zip dosyası ayıklamak için nasıl basit bir örnek
Code reference ve
Zip samples.
ALTERNATİF:
ben sadece ZIP dosyalarını desteklemek için gerekli çünkü daha basit çözüm ile sona erdi yukarıda ı izah neyi yaptıktan sonra. System.IO.Compression
ve PCLStorage
'da bulunan ZipArchive Class
kullandım, bu çözümle SharpZipLib.Portable
kullanmayın.
public async void DonwLoadAndStoreZipFile()
{
var bytes = await DownloadImageAsync(https://github.com/fluidicon.png);
// IFolder interface comes from PCLStorage
IFolder rootFolder = FileSystem.Current.LocalStorage;
IFolder folder = await rootFolder.CreateFolderAsync("zipFolder", CreationCollisionOption.OpenIfExists);
IFile file = await folder.CreateFileAsync("test.zip" , CreationCollisionOption.OpenIfExists);
using (Stream stream = await file.OpenAsync(FileAccess.ReadAndWrite))
{
await stream.WriteAsync(bytes, 0, bytes.Length);
using(ZipArchive archive = new ZipArchive(stream))
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
IFile zipEntryFile = await rootFolder.CreateFileAsync(entry.Name, CreationCollisionOption.FailIfExists);
using (Stream outPutStream = await zipEntryFile.OpenAsync(FileAccess.ReadAndWrite))
{
await entry.Open().CopyToAsync(outPutStream);
}
}
}
}
}
: Burada
versiyonu