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
zipArchive
ZipArchiveZipArchive containing the nupkg data.
PackageArchiveReader(ZipArchive, IFrameworkNameProvider, IFrameworkCompatibilityProvider)
Nupkg package reader
public PackageArchiveReader(ZipArchive zipArchive, IFrameworkNameProvider frameworkProvider, IFrameworkCompatibilityProvider compatibilityProvider)
Parameters
zipArchive
ZipArchiveZipArchive containing the nupkg data.
frameworkProvider
IFrameworkNameProviderFramework mapping provider for NuGetFramework parsing.
compatibilityProvider
IFrameworkCompatibilityProviderFramework compatibility provider.
PackageArchiveReader(Stream)
Nupkg package reader
public PackageArchiveReader(Stream stream)
Parameters
stream
StreamNupkg data stream.
PackageArchiveReader(Stream, IFrameworkNameProvider, IFrameworkCompatibilityProvider)
Nupkg package reader
public PackageArchiveReader(Stream stream, IFrameworkNameProvider frameworkProvider, IFrameworkCompatibilityProvider compatibilityProvider)
Parameters
stream
StreamNupkg data stream.
frameworkProvider
IFrameworkNameProviderFramework mapping provider for NuGetFramework parsing.
compatibilityProvider
IFrameworkCompatibilityProviderFramework compatibility provider.
PackageArchiveReader(Stream, bool)
Nupkg package reader
public PackageArchiveReader(Stream stream, bool leaveStreamOpen)
Parameters
stream
StreamNupkg data stream.
leaveStreamOpen
boolIf 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
stream
StreamNupkg data stream.
leaveStreamOpen
boolleave nupkg stream open
frameworkProvider
IFrameworkNameProviderFramework mapping provider for NuGetFramework parsing.
compatibilityProvider
IFrameworkCompatibilityProviderFramework compatibility provider.
PackageArchiveReader(string, IFrameworkNameProvider, IFrameworkCompatibilityProvider)
public PackageArchiveReader(string filePath, IFrameworkNameProvider frameworkProvider = null, IFrameworkCompatibilityProvider compatibilityProvider = null)
Parameters
filePath
stringframeworkProvider
IFrameworkNameProvidercompatibilityProvider
IFrameworkCompatibilityProvider
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
verifierSettings
SignedPackageVerifierSettingsPackage 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
destination
stringThe destination folder path.
packageFiles
IEnumerable<string>The package files to copy.
extractFile
ExtractPackageFileDelegateA package file extraction delegate.
logger
ILoggerA logger.
token
CancellationTokenA 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
nupkgFilePath
stringThe destination file path.
cancellationToken
CancellationTokenA cancellation token.
Returns
- Task<string>
A task that represents the asynchronous operation. The task result (Result) returns a string.
Exceptions
- ArgumentException
Thrown if
nupkgFilePath
is eithernull
or an empty string.- OperationCanceledException
Thrown if
cancellationToken
is cancelled.
Dispose(bool)
protected override void Dispose(bool disposing)
Parameters
disposing
bool
EnumeratePackageEntries(IEnumerable<string>, string)
public IEnumerable<ZipFilePair> EnumeratePackageEntries(IEnumerable<string> packageFiles, string packageDirectory)
Parameters
packageFiles
IEnumerable<string>packageDirectory
string
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
hashAlgorithmName
HashAlgorithmNametoken
CancellationToken
Returns
GetContentHash(CancellationToken, Func<string>)
Get contenthash for a package.
public override string GetContentHash(CancellationToken token, Func<string> GetUnsignedPackageHash = null)
Parameters
token
CancellationTokenGetUnsignedPackageHash
Func<string>
Returns
GetEntry(string)
public ZipArchiveEntry GetEntry(string packageFile)
Parameters
packageFile
string
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
folder
stringFolder path
Returns
- IEnumerable<string>
An enumerable of files under specified folder.
GetPrimarySignatureAsync(CancellationToken)
Get package signature.
public override Task<PrimarySignature> GetPrimarySignatureAsync(CancellationToken token)
Parameters
token
CancellationToken
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
path
string
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
token
CancellationToken
Returns
ThrowIfZipReadStreamIsNull()
protected void ThrowIfZipReadStreamIsNull()
ValidateIntegrityAsync(SignatureContent, CancellationToken)
Checks for the integrity of a package
public override Task ValidateIntegrityAsync(SignatureContent signatureContent, CancellationToken token)
Parameters
signatureContent
SignatureContentSignatureContent with expected hash value and hash algorithm used
token
CancellationToken
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
token
CancellationToken