Class PackageArchiveReader
Reads a development nupkg
public class PackageArchiveReader : PackageReaderBase, IPackageCoreReader, IPackageContentReader, IAsyncPackageCoreReader, IAsyncPackageContentReader, ISignedPackageReader, IDisposable
- Inheritance
-
PackageArchiveReader
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
PackageArchiveReader(ZipArchive)
Nupkg package reader
public PackageArchiveReader(ZipArchive zipArchive)
Parameters
zipArchiveZipArchiveZipArchive containing the nupkg data.
PackageArchiveReader(ZipArchive, IFrameworkNameProvider, IFrameworkCompatibilityProvider)
Nupkg package reader
public PackageArchiveReader(ZipArchive zipArchive, IFrameworkNameProvider frameworkProvider, IFrameworkCompatibilityProvider compatibilityProvider)
Parameters
zipArchiveZipArchiveZipArchive containing the nupkg data.
frameworkProviderIFrameworkNameProviderFramework mapping provider for NuGetFramework parsing.
compatibilityProviderIFrameworkCompatibilityProviderFramework compatibility provider.
PackageArchiveReader(Stream)
Nupkg package reader
public PackageArchiveReader(Stream stream)
Parameters
streamStreamNupkg data stream.
PackageArchiveReader(Stream, IFrameworkNameProvider, IFrameworkCompatibilityProvider)
Nupkg package reader
public PackageArchiveReader(Stream stream, IFrameworkNameProvider frameworkProvider, IFrameworkCompatibilityProvider compatibilityProvider)
Parameters
streamStreamNupkg data stream.
frameworkProviderIFrameworkNameProviderFramework mapping provider for NuGetFramework parsing.
compatibilityProviderIFrameworkCompatibilityProviderFramework compatibility provider.
PackageArchiveReader(Stream, bool)
Nupkg package reader
public PackageArchiveReader(Stream stream, bool leaveStreamOpen)
Parameters
streamStreamNupkg data stream.
leaveStreamOpenboolIf true the nupkg stream will not be closed by the zip reader.
PackageArchiveReader(Stream, bool, IFrameworkNameProvider, IFrameworkCompatibilityProvider)
Nupkg package reader
public PackageArchiveReader(Stream stream, bool leaveStreamOpen, IFrameworkNameProvider frameworkProvider, IFrameworkCompatibilityProvider compatibilityProvider)
Parameters
streamStreamNupkg data stream.
leaveStreamOpenboolleave nupkg stream open
frameworkProviderIFrameworkNameProviderFramework mapping provider for NuGetFramework parsing.
compatibilityProviderIFrameworkCompatibilityProviderFramework compatibility provider.
PackageArchiveReader(string, IFrameworkNameProvider, IFrameworkCompatibilityProvider)
public PackageArchiveReader(string filePath, IFrameworkNameProvider frameworkProvider = null, IFrameworkCompatibilityProvider compatibilityProvider = null)
Parameters
filePathstringframeworkProviderIFrameworkNameProvidercompatibilityProviderIFrameworkCompatibilityProvider
Properties
SigningSpecifications
Signature specifications.
protected SigningSpecifications SigningSpecifications { get; }
Property Value
ZipReadStream
Stream underlying the ZipArchive. Used to do signature verification on a SignedPackageArchive. If this is null then we cannot perform signature verification.
protected Stream ZipReadStream { get; set; }
Property Value
Methods
CanVerifySignedPackages(SignedPackageVerifierSettings)
Indicates if the the ISignedPackageReader instance can verify signed packages.
public override bool CanVerifySignedPackages(SignedPackageVerifierSettings verifierSettings)
Parameters
verifierSettingsSignedPackageVerifierSettingsPackage verification settings. Include information about what is allowed.
Returns
Exceptions
- SignatureException
if the ISignedPackageReader does not support signed packages
CopyFiles(string, IEnumerable<string>, ExtractPackageFileDelegate, ILogger, CancellationToken)
Copies files from a package to a new location.
public override IEnumerable<string> CopyFiles(string destination, IEnumerable<string> packageFiles, ExtractPackageFileDelegate extractFile, ILogger logger, CancellationToken token)
Parameters
destinationstringThe destination folder path.
packageFilesIEnumerable<string>The package files to copy.
extractFileExtractPackageFileDelegateA package file extraction delegate.
loggerILoggerA logger.
tokenCancellationTokenA cancellation token.
Returns
- IEnumerable<string>
An enumerable of paths of files copied to the destination.
CopyNupkgAsync(string, CancellationToken)
Asynchronously copies a package to the specified destination file path.
public override Task<string> CopyNupkgAsync(string nupkgFilePath, CancellationToken cancellationToken)
Parameters
nupkgFilePathstringThe destination file path.
cancellationTokenCancellationTokenA cancellation token.
Returns
- Task<string>
A task that represents the asynchronous operation. The task result (Result) returns a string.
Exceptions
- ArgumentException
Thrown if
nupkgFilePathis eithernullor an empty string.- OperationCanceledException
Thrown if
cancellationTokenis cancelled.
Dispose(bool)
protected override void Dispose(bool disposing)
Parameters
disposingbool
EnumeratePackageEntries(IEnumerable<string>, string)
public IEnumerable<ZipFilePair> EnumeratePackageEntries(IEnumerable<string> packageFiles, string packageDirectory)
Parameters
packageFilesIEnumerable<string>packageDirectorystring
Returns
ExtractFile(string, string, ILogger)
public string ExtractFile(string packageFile, string targetFilePath, ILogger logger)
Parameters
Returns
GetArchiveHashAsync(HashAlgorithmName, CancellationToken)
Gets the hash of an archive to be embedded in the package signature.
public override Task<byte[]> GetArchiveHashAsync(HashAlgorithmName hashAlgorithmName, CancellationToken token)
Parameters
hashAlgorithmNameHashAlgorithmNametokenCancellationToken
Returns
GetContentHash(CancellationToken, Func<string>)
Get contenthash for a package.
public override string GetContentHash(CancellationToken token, Func<string> GetUnsignedPackageHash = null)
Parameters
tokenCancellationTokenGetUnsignedPackageHashFunc<string>
Returns
GetEntry(string)
public ZipArchiveEntry GetEntry(string packageFile)
Parameters
packageFilestring
Returns
GetFiles()
Gets all files in the package.
public override IEnumerable<string> GetFiles()
Returns
- IEnumerable<string>
An enumerable of files in the package.
GetFiles(string)
Gets files in a folder in the package.
public override IEnumerable<string> GetFiles(string folder)
Parameters
folderstringFolder path
Returns
- IEnumerable<string>
An enumerable of files under specified folder.
GetPrimarySignatureAsync(CancellationToken)
Get package signature.
public override Task<PrimarySignature> GetPrimarySignatureAsync(CancellationToken token)
Parameters
tokenCancellationToken
Returns
Remarks
Returns a null if the package is unsigned.
GetStream(string)
Gets a file stream from the package.
public override Stream GetStream(string path)
Parameters
pathstring
Returns
- Stream
A stream for a file in the package.
IsSignedAsync(CancellationToken)
Check if a package contains signing information.
public override Task<bool> IsSignedAsync(CancellationToken token)
Parameters
tokenCancellationToken
Returns
ThrowIfZipReadStreamIsNull()
protected void ThrowIfZipReadStreamIsNull()
ValidateIntegrityAsync(SignatureContent, CancellationToken)
Checks for the integrity of a package
public override Task ValidateIntegrityAsync(SignatureContent signatureContent, CancellationToken token)
Parameters
signatureContentSignatureContentSignatureContent with expected hash value and hash algorithm used
tokenCancellationToken
Returns
ValidatePackageEntriesAsync(CancellationToken)
Validate all files in package are not traversed outside of the expected extraction path. Eg: file entry like ../../foo.dll can get outside of the expected extraction path.
public Task ValidatePackageEntriesAsync(CancellationToken token)
Parameters
tokenCancellationToken