src/NuGetGallery.Core/Services/CoreReadmeFileService.cs
/// <summary>
/// Save the readme file from package stream. This method should throw if the package
/// does not have an embedded readme file 
/// </summary>
/// <param name="package">Package information.</param>
/// <param name="packageStream">Package stream with .nupkg contents.</param>
Save the readme file from package stream. This method should throw if the package
does not have an embedded readme file
Save the readme file from package stream . This method should throw if the package does not have an embedded readme file
public async Task ExtractAndSaveReadmeFileAsync(Package package, Stream packageStream)
        {
            if (package == null)
            {
                throw new ArgumentNullException(nameof(package));
            }
            if (packageStream == null)
            {
                throw new ArgumentNullException(nameof(packageStream));
            }
            packageStream.Seek(0, SeekOrigin.Begin);
            using (var packageArchiveReader = new PackageArchiveReader(packageStream, leaveStreamOpen: true))
            {
                var packageMetadata = PackageMetadata.FromNuspecReader(packageArchiveReader.GetNuspecReader(), strict: true);
                if (string.IsNullOrWhiteSpace(packageMetadata.ReadmeFile))
                {
                    throw new InvalidOperationException("No readme file specified in the nuspec");
                }
                var filename = FileNameHelper.GetZipEntryPath(packageMetadata.ReadmeFile);
                var ReadmeFileEntry = packageArchiveReader.GetEntry(filename); 
                using (var readmeFileStream = ReadmeFileEntry.Open())
                {
                    await SaveReadmeFileAsync(package, readmeFileStream);
                }
            }
        }
public async Task ExtractAndSaveReadmeFileAsync ( Package package , Stream packageStream ) { if ( package == null ) { throw new ArgumentNullException ( nameof ( package ) ) ; } if ( packageStream == null ) { throw new ArgumentNullException ( nameof ( packageStream ) ) ; } packageStream . Seek ( 0 , SeekOrigin . Begin ) ; using ( var packageArchiveReader = new PackageArchiveReader ( packageStream , leaveStreamOpen : true ) ) { var packageMetadata = PackageMetadata . FromNuspecReader ( packageArchiveReader . GetNuspecReader ( ) , strict : true ) ; if ( string . IsNullOrWhiteSpace ( packageMetadata . ReadmeFile ) ) { throw new InvalidOperationException ( " " ) ; } var filename = FileNameHelper . GetZipEntryPath ( packageMetadata . ReadmeFile ) ; var ReadmeFileEntry = packageArchiveReader . GetEntry ( filename ) ; using ( var readmeFileStream = ReadmeFileEntry . Open ( ) ) { await SaveReadmeFileAsync ( package , readmeFileStream ) ; } } }
Save the readme file from package stream.
Save the readme file from package stream .
// throws on non-existent file
package
Package
None
packageStream
Stream
Package stream with .nupkg contents.
Package stream with . nupkg contents .