Exemple #1
0
 /// <summary>
 /// Open a .dll file.
 /// </summary>
 /// <param name="filename"></param>
 /// <param name="packageInfo"></param>
 /// <returns>file provider</returns>
 public IFileProvider OpenFile(string filename, IPackageLoadInfo packageInfo)
 {
     try
     {
         return(DllFileProvider.OpenFile(filename, packageInfo?.LastModified));
     }
     catch (Exception e) when(e is InvalidDataException || e is FormatException || e is BadImageFormatException)
     {
         throw new PackageException.LoadError(filename, e);
     }
 }
Exemple #2
0
 /// <summary>
 /// Use <paramref name="stream"/> to access contents of a .dll file.
 /// </summary>
 /// <param name="stream"></param>
 /// <param name="packageInfo"></param>
 /// <returns>file provider</returns>
 public IFileProvider UseStream(Stream stream, IPackageLoadInfo packageInfo)
 {
     try
     {
         return(DllFileProvider.UseStream(stream, packageInfo?.LastModified));
     }
     catch (Exception e) when(e is InvalidDataException || e is FormatException || e is BadImageFormatException)
     {
         throw new PackageException.LoadError(stream is FileStream fs ? fs.Name : null, e);
     }
 }
 /// <summary>
 /// Opens a .tar file with zero to multiple open file handles.
 /// Is thread-safe and thread-scalable (concurrent use is possible).
 /// </summary>
 /// <param name="filepath"></param>
 /// <param name="packageInfo">(optional) clues about the file that is being opened</param>
 /// <returns>file provider to the contents of the package</returns>
 /// <exception cref="IOException">On I/O error</exception>
 /// <exception cref="PackageException.LoadError">on .tar error</exception>
 public IFileProvider OpenFile(string filepath, IPackageLoadInfo packageInfo)
 {
     try
     {
         return(new TarFileProvider(filepath, packageInfo?.Path, packageInfo?.LastModified, convertBackslashesToSlashes));
     }
     catch (Exception e) when(e is InvalidDataException || e is FormatException || e is BadImageFormatException)
     {
         throw new PackageException.LoadError(filepath, e);
     }
 }
 /// <summary>
 /// Reads .tar file from a stream. Takes ownership of the stream (closes it).
 /// Is thread-safe, but not thread-scalable (locks threads).
 /// </summary>
 /// <param name="stream"></param>
 /// <param name="packageInfo">(optional) clues about the file that is being opened</param>
 /// <returns>file provider to the contents of the package</returns>
 /// <exception cref="IOException">On I/O error</exception>
 /// <exception cref="PackageException.LoadError">on .tar error</exception>
 public IFileProvider UseStream(Stream stream, IPackageLoadInfo packageInfo)
 {
     try
     {
         return(new TarFileProvider(stream, packageInfo?.Path, packageInfo?.LastModified, convertBackslashesToSlashes).AddDisposable(stream));
     }
     catch (Exception e) when(e is InvalidDataException || e is FormatException || e is BadImageFormatException)
     {
         throw new PackageException.LoadError(null, e);
     }
 }
 /// <summary>
 /// Read archive from a byte[]. The caller must close the returned file provider.
 /// </summary>
 /// <param name="data"></param>
 /// <param name="packageInfo">(optional) clues about the file that is being opened</param>
 /// <returns>file provider to the contents of the package</returns>
 public IFileProvider UseBytes(byte[] data, IPackageLoadInfo packageInfo = null)
 {
     try
     {
         Func <TarArchive> opener = () => TarArchive.Open(new MemoryStream(data));
         return(new TarFileProvider(opener, packageInfo?.Path, packageInfo?.LastModified));
     }
     catch (Exception e) when(e is InvalidDataException || e is FormatException || e is BadImageFormatException)
     {
         throw new PackageException.LoadError(null, e);
     }
 }
        /// <summary>
        /// Opens a .gz file with zero to multiple open file handles.
        /// Is thread-safe and thread-scalable (concurrent use is possible).
        /// </summary>
        /// <param name="filepath"></param>
        /// <param name="packageInfo">(optional) clues about the file that is being opened</param>
        /// <returns>file provider to the contents of the package</returns>
        /// <exception cref="IOException">On I/O error</exception>
        /// <exception cref="PackageException.LoadError">on .gz error</exception>
        public IFileProvider OpenFile(string filepath, IPackageLoadInfo packageInfo)
        {
            string entryName = ExtractName(packageInfo?.Path) ?? fallbackEntryName;

            try
            {
                return(new GZipFileProvider(filepath, entryName, packageInfo?.Path, packageInfo?.LastModified));
            }
            catch (Exception e) when(e is InvalidDataException || e is FormatException || e is BadImageFormatException)
            {
                throw new PackageException.LoadError(filepath, e);
            }
        }
Exemple #7
0
        /// <summary>
        /// Read archive from a byte[]. The caller must close the returned file provider.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="packageInfo"></param>
        /// <returns></returns>
        public IFileProvider UseBytes(byte[] data, IPackageLoadInfo packageInfo = null)
        {
            string entryName = ExtractName(packageInfo?.Path) ?? fallbackEntryName;

            try
            {
                return(new BZip2FileProvider(data, entryName, packageInfo?.Path, packageInfo?.LastModified));
            }
            catch (Exception e) when(e is InvalidDataException || e is FormatException || e is BadImageFormatException)
            {
                throw new PackageException.LoadError(null, e);
            }
        }
        /// <summary>
        /// Reads .gz file from a stream. Takes ownership of the stream (closes it).
        /// Is thread-safe, but not thread-scalable (locks threads).
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="packageInfo">(optional) clues about the file that is being opened</param>
        /// <returns>file provider to the contents of the package</returns>
        /// <exception cref="IOException">On I/O error</exception>
        /// <exception cref="PackageException.LoadError">on .gz error</exception>
        public IFileProvider UseStream(Stream stream, IPackageLoadInfo packageInfo)
        {
            string entryName = ExtractName(packageInfo?.Path) ?? fallbackEntryName;

            try
            {
                return(new GZipFileProvider(stream, entryName, packageInfo?.Path, packageInfo?.LastModified).AddDisposable(stream));
            }
            catch (Exception e) when(e is InvalidDataException || e is FormatException || e is BadImageFormatException)
            {
                try { stream.Dispose(); } catch (Exception) { }
                throw new PackageException.LoadError(null, e);
            }
        }
        /// <summary>
        /// Read archive from a byte[]. The caller must close the returned file provider.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="packageInfo"></param>
        /// <returns></returns>
        public IFileProvider UseBytes(byte[] data, IPackageLoadInfo packageInfo = null)
        {
            string entryName = ExtractName(packageInfo?.Path) ?? fallbackEntryName;

            try
            {
                Func <GZipArchive> opener = () => GZipArchive.Open(new MemoryStream(data));
                return(new GZipFileProvider(opener, entryName, packageInfo?.Path, packageInfo?.LastModified));
            }
            catch (Exception e) when(e is InvalidDataException || e is FormatException || e is BadImageFormatException)
            {
                throw new PackageException.LoadError(null, e);
            }
        }
Exemple #10
0
        /// <summary>
        /// Load from byte[]
        /// </summary>
        /// <param name="data"></param>
        /// <param name="packageInfo">(optional) clues about the file that is being opened</param>
        /// <returns></returns>
        public IFileProvider UseBytes(byte[] data, IPackageLoadInfo packageInfo)
        {
            AppDomain appDomain = AppDomain.CreateDomain(nameof(ManifestEmbeddedFileProvider) + "-" + Guid.NewGuid());

            try
            {
                Assembly asm = appDomain.Load(data);
                Microsoft.Extensions.FileProviders.ManifestEmbeddedFileProvider embeddedFileProvider = new Microsoft.Extensions.FileProviders.ManifestEmbeddedFileProvider(asm);
                AppDomainUnloader disposable   = new AppDomainUnloader(appDomain);
                IFileProvider     fileProvider = new FileProviderHandle(o => (o as IDisposable).Dispose(), disposable, embeddedFileProvider);
                return(fileProvider);
            }
            catch (Exception e)
            {
                AppDomain.Unload(appDomain);
                throw new PackageException.LoadError(null, e);
            }
        }
 /// <summary>
 /// Opens a .zip file with zero to multiple open file handles.
 /// Is thread-safe and thread-scalable (concurrent use is possible).
 /// </summary>
 /// <param name="filename"></param>
 /// <param name="packageInfo">(optional) clues about the file that is being opened</param>
 /// <returns>file provider that represents the package</returns>
 /// <exception cref="IOException">On I/O error</exception>
 /// <exception cref="PackageException.LoadError">on file format error</exception>
 public IFileProvider OpenFile(string filename, IPackageLoadInfo packageInfo)
 {
     try
     {
         return(new ZipFileProvider(filename, default, packageInfo?.Path, packageInfo?.LastModified));