func FetchNamedImagesFromZIP(zipPath string, includeOverlay bool, storageClient *storage.Client, acceptedFiles []string) (map[string]image.Image, error) {
	pngDats := make(map[string]image.Image)

	permittedFilenames := make(map[string]struct{})
	for _, v := range acceptedFiles {
		permittedFilenames[v] = struct{}{}
	}

	// Read the zip file into memory still compressed - either from a local
	// file, or from Google storage, depending on the prefix you provide.
	readerAt, zipNBytes, err := MaybeOpenFromGoogleStorage(zipPath, storageClient)
	if err != nil {
		return nil, err
	}
	defer readerAt.Close()

	// Since we read all images, just do it all at once for more efficient
	// transfer over the wire.
	allBytes, err := ioutil.ReadAll(readerAt)
	if err != nil {
		return nil, err
	}

	zipBytes := bytes.NewReader(allBytes)

	rc, err := zip.NewReader(zipBytes, zipNBytes)
	if err != nil {
		return nil, err
	}

	// Iterate over the files within the Zip
	for _, v := range rc.File {

		// Don't burn cycles parsing non-permitted filenames
		if _, allowed := permittedFilenames[v.Name]; len(permittedFilenames) > 0 && !allowed {
			continue
		}

		// Read all DICOMs into images
		dicomReader, err := v.Open()
		if err != nil {
			return nil, err
		}
		// We're in a loop so try to keep track of when to close this file this
		// manually rather than relying on defer.
		// defer dicomReader.Close()

		img, err := ExtractDicomFromReader(dicomReader, int64(v.UncompressedSize64), includeOverlay)
		if err != nil {
			// If it's not a DICOM file, mention that and move on
			log.Println(err)
			dicomReader.Close()
			continue
		}

		pngDats[v.Name] = img
		dicomReader.Close()
	}

	return pngDats, nil
}
// FetchNamedImagesFromZIP fetches images from DICOM files within a Zip file.
// The Zip file may be local or on Google Storage (if path begins with gs://).
// The images are returned in a map, keyed to the DICOM name:
// map[dicom_name]image. If a non-nil slice of filenames is passed, then only
// filenames that appear in this slice will be processed and returned.
FetchNamedImagesFromZIP fetches images from DICOM files within a Zip file.
The Zip file may be local or on Google Storage (if path begins with gs://).
The images are returned in a map, keyed to the DICOM name:
map[dicom_name]image. If a non-nil slice of filenames is passed, then only
filenames that appear in this slice will be processed and returned.
// FetchNamedImagesFromZIP fetches images from DICOM files within a Zip file . // The Zip file may be local or on Google Storage ( if path begins with gs : // ) . // The images are returned in a map keyed to the DICOM name : // map [ dicom_name ] image . If a non - nil slice of filenames is passed then only // filenames that appear in this slice will be processed and returned .
func FetchNamedImagesFromZIP(zipPath string, includeOverlay bool, storageClient *storage.Client, acceptedFiles []string) (map[string]image.Image, error) {
	pngDats := make(map[string]image.Image)
	permittedFilenames := make(map[string]struct{})
	for _, v := range acceptedFiles {
		permittedFilenames[v] = struct{}{}
	}
	readerAt, zipNBytes, err := MaybeOpenFromGoogleStorage(zipPath, storageClient)
	if err != nil {
		return nil, err
	}
	defer readerAt.Close()
	allBytes, err := ioutil.ReadAll(readerAt)
	if err != nil {
		return nil, err
	}
	zipBytes := bytes.NewReader(allBytes)
	rc, err := zip.NewReader(zipBytes, zipNBytes)
	if err != nil {
		return nil, err
	}
	for _, v := range rc.File {
		if _, allowed := permittedFilenames[v.Name]; len(permittedFilenames) > 0 && !allowed {
			continue
		}
		dicomReader, err := v.Open()
		if err != nil {
			return nil, err
		}
		img, err := ExtractDicomFromReader(dicomReader, int64(v.UncompressedSize64), includeOverlay)
		if err != nil {
			log.Println(err)
			dicomReader.Close()
			continue
		}
		pngDats[v.Name] = img
		dicomReader.Close()
	}
	return pngDats, nil
}
func FetchNamedImagesFromZIP ( zipPath string , includeOverlay bool , storageClient * storage . Client , acceptedFiles [ ] string ) ( map [ string ] image . Image , error ) { pngDats := make ( map [ string ] image . Image ) permittedFilenames := make ( map [ string ] struct { } ) for _ , v := range acceptedFiles { permittedFilenames [ v ] = struct { } { } } readerAt , zipNBytes , err := MaybeOpenFromGoogleStorage ( zipPath , storageClient ) if err != nil { return nil , err } defer readerAt . Close ( ) allBytes , err := ioutil . ReadAll ( readerAt ) if err != nil { return nil , err } zipBytes := bytes . NewReader ( allBytes ) rc , err := zip . NewReader ( zipBytes , zipNBytes ) if err != nil { return nil , err } for _ , v := range rc . File { if _ , allowed := permittedFilenames [ v . Name ] ; len ( permittedFilenames ) > 0 && ! allowed { continue } dicomReader , err := v . Open ( ) if err != nil { return nil , err } img , err := ExtractDicomFromReader ( dicomReader , int64 ( v . UncompressedSize64 ) , includeOverlay ) if err != nil { log . Println ( err ) dicomReader . Close ( ) continue } pngDats [ v . Name ] = img dicomReader . Close ( ) } return pngDats , nil }
FetchNamedImagesFromZIP fetches images from DICOM files within a Zip file.
FetchNamedImagesFromZIP fetches images from DICOM files within a Zip file .
// Read the zip file into memory still compressed - either from a local // file, or from Google storage, depending on the prefix you provide. // Since we read all images, just do it all at once for more efficient // transfer over the wire. // Iterate over the files within the Zip // Don't burn cycles parsing non-permitted filenames // Read all DICOMs into images // We're in a loop so try to keep track of when to close this file this // manually rather than relying on defer. // defer dicomReader.Close() // If it's not a DICOM file, mention that and move on