• Lexical
Show / Hide Table of Contents
  • Lexical.FileSystem
    • Introduction
    • Abstractions
      • IFileSystem
        • IFileSystem
        • IFileSystemBrowse
        • IFileSystemCreateDirectory
        • IFileSystemDelete
        • IFileSystemFileAttribute
        • IFileSystemMount
        • IFileSystemMove
        • IFileSystemObserve
        • IFileSystemOpen
      • IEvent
      • IEntry
      • IOption
      • IToken
    • FileSystem
    • VirtualFileSystem
    • MemoryFileSystem
    • EmbeddedFileSystem
    • HttpFileSystem
    • Decoration
    • IFileProvider
    • Utility
      • DisposeList
      • FileScanner
      • VisitTree
      • File Operation
  • Lexical.FileProvider
    • Introduction
    • Package
    • Package.Abstractions
    • Root
    • Zip
    • Dll
    • SharpCompress
    • SharpZipLib
    • FileScanner
    • Utils
  • Lexical.Localization
    • Introduction
    • Tutorial
    • Asset
      • IAsset
      • IStringAsset
    • Line
      • ILine
      • ILineFactory
      • ILineRoot
      • ILineFormat
      • ILineLogger
      • LineComparer
    • File
      • ILineReader
      • ILineWriter
      • Ini
      • Json
      • Xml
      • Resx
      • Resources
    • Miscellaneous
      • Plurality
      • ICulturePolicy
      • IStringFormat
      • Dependency Injection
    • Practices
      • Class Library
      • Class Library DI
      • Class Library DI opt.
  • Lexical.Utilities
    • Introduction
    • UnicodeString
    • FileScanner
    • Permutation
    • Tuples
    • StructList

Lexical.FileProvider.Zip

new ZipFileProvider(string) constructs a file provider that reads .zip contents. Content can be read concurrently as file provider opens new file handles as needed.

ZipFileProvider fileProvider = new ZipFileProvider("mydata.zip");

Another constructor is new ZipFileProvider(Stream). Note however, that as stream has only one file pointer, the content can be accessed only by one thread at a time. Concurrent threads have to wait.

// Open some stream
Stream stream = new FileStream("mydata.zip", FileMode.Open);

// Use stream as zip file.
ZipFileProvider fileProvider = new ZipFileProvider(stream).AddDisposable(stream);

File provider must be disposed after use.

fileProvider.Dispose();

Belated dispose can be added to the file provider. They are disposed once the fileprovider is disposed and all its streams.

// Create file provider
ZipFileProvider fileProvider = new ZipFileProvider("mydata.zip");
// Add disposable for belated dispose
fileProvider.AddBelatedDispose(new _Disposable_());
// Open stream
Stream s = fileProvider
        .GetFileInfo("Lexical.Localization.Tests.dll")
        .CreateReadStream();
// Dispose file provider
fileProvider.Dispose();
// Dispose the open stream  --  _Disposable_ is disposed here.
s.Dispose();

Package Loader

Lexical.FileProvider.PackageLoader.Zip can be used as a component of PackageFileLoader, making possible to drill down into .zip files.

// Create root file provider
PhysicalFileProvider root = new PhysicalFileProvider(Directory.GetCurrentDirectory());

// Create package options
IPackageFileProviderOptions options =
    new PackageFileProviderOptions()
    .AddPackageLoaders(Lexical.FileProvider.PackageLoader.Zip.Singleton);

// Create package file provider
IPackageFileProvider fileProvider = new PackageFileProvider(root, options).AddDisposable(root);

Lexical.FileProvider.PackageLoader.Zip can be constructed to open other file extensions that are of zip file format, such as .nupkg.

IPackageFileProviderOptions options = new PackageFileProviderOptions()
    .AddPackageLoaders( new Lexical.FileProvider.PackageLoader.Zip("\\.nupkg") );

Links

  • Lexical.FileProvider.Zip (NuGet)
    • ZipFileProvider
    • ZipPackageLoader
  • Lexical.FileProvider.Abstractions (NuGet)
    • IPackageLoader
  • Microsoft.Extensions.FileProviders.Abstractions (NuGet)
    • IFileProvider
Back to top Copyright © 2015-2020 Toni Kalajainen