Table of Contents

Class PackageArchiveReader

Namespace
NuGet.Packaging
Assembly
Chocolatey.NuGet.Packaging.dll

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 ZipArchive

ZipArchive containing the nupkg data.

PackageArchiveReader(ZipArchive, IFrameworkNameProvider, IFrameworkCompatibilityProvider)

Nupkg package reader

public PackageArchiveReader(ZipArchive zipArchive, IFrameworkNameProvider frameworkProvider, IFrameworkCompatibilityProvider compatibilityProvider)

Parameters

zipArchive ZipArchive

ZipArchive containing the nupkg data.

frameworkProvider IFrameworkNameProvider

Framework mapping provider for NuGetFramework parsing.

compatibilityProvider IFrameworkCompatibilityProvider

Framework compatibility provider.

PackageArchiveReader(Stream)

Nupkg package reader

public PackageArchiveReader(Stream stream)

Parameters

stream Stream

Nupkg data stream.

PackageArchiveReader(Stream, IFrameworkNameProvider, IFrameworkCompatibilityProvider)

Nupkg package reader

public PackageArchiveReader(Stream stream, IFrameworkNameProvider frameworkProvider, IFrameworkCompatibilityProvider compatibilityProvider)

Parameters

stream Stream

Nupkg data stream.

frameworkProvider IFrameworkNameProvider

Framework mapping provider for NuGetFramework parsing.

compatibilityProvider IFrameworkCompatibilityProvider

Framework compatibility provider.

PackageArchiveReader(Stream, bool)

Nupkg package reader

public PackageArchiveReader(Stream stream, bool leaveStreamOpen)

Parameters

stream Stream

Nupkg data stream.

leaveStreamOpen bool

If 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 Stream

Nupkg data stream.

leaveStreamOpen bool

leave nupkg stream open

frameworkProvider IFrameworkNameProvider

Framework mapping provider for NuGetFramework parsing.

compatibilityProvider IFrameworkCompatibilityProvider

Framework compatibility provider.

PackageArchiveReader(string, IFrameworkNameProvider, IFrameworkCompatibilityProvider)

public PackageArchiveReader(string filePath, IFrameworkNameProvider frameworkProvider = null, IFrameworkCompatibilityProvider compatibilityProvider = null)

Parameters

filePath string
frameworkProvider IFrameworkNameProvider
compatibilityProvider IFrameworkCompatibilityProvider

Properties

SigningSpecifications

Signature specifications.

protected SigningSpecifications SigningSpecifications { get; }

Property Value

SigningSpecifications

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

Stream

Methods

CanVerifySignedPackages(SignedPackageVerifierSettings)

Indicates if the the ISignedPackageReader instance can verify signed packages.

public override bool CanVerifySignedPackages(SignedPackageVerifierSettings verifierSettings)

Parameters

verifierSettings SignedPackageVerifierSettings

Package verification settings. Include information about what is allowed.

Returns

bool

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 string

The destination folder path.

packageFiles IEnumerable<string>

The package files to copy.

extractFile ExtractPackageFileDelegate

A package file extraction delegate.

logger ILogger

A logger.

token CancellationToken

A 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 string

The destination file path.

cancellationToken CancellationToken

A 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 either null 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

IEnumerable<ZipFilePair>

ExtractFile(string, string, ILogger)

public string ExtractFile(string packageFile, string targetFilePath, ILogger logger)

Parameters

packageFile string
targetFilePath string
logger ILogger

Returns

string

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 HashAlgorithmName
token CancellationToken

Returns

Task<byte[]>

GetContentHash(CancellationToken, Func<string>)

Get contenthash for a package.

public override string GetContentHash(CancellationToken token, Func<string> GetUnsignedPackageHash = null)

Parameters

token CancellationToken
GetUnsignedPackageHash Func<string>

Returns

string

GetEntry(string)

public ZipArchiveEntry GetEntry(string packageFile)

Parameters

packageFile string

Returns

ZipArchiveEntry

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 string

Folder 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

Task<PrimarySignature>

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

Task<bool>

True if the package is signed.

ThrowIfZipReadStreamIsNull()

protected void ThrowIfZipReadStreamIsNull()

ValidateIntegrityAsync(SignatureContent, CancellationToken)

Checks for the integrity of a package

public override Task ValidateIntegrityAsync(SignatureContent signatureContent, CancellationToken token)

Parameters

signatureContent SignatureContent

SignatureContent with expected hash value and hash algorithm used

token CancellationToken

Returns

Task

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

Returns

Task