// epubPackage gets the filename of the first OPF package document from the OCF
// container.
//
// OCF containers can have technically more than one package document, but
// like most reading systems, we'll just use the first one.
epubPackage gets the filename of the first OPF package document from the OCF
container.

OCF containers can have technically more than one package document, but
like most reading systems, we'll just use the first one.
// epubPackage gets the filename of the first OPF package document from the OCF // container . // // OCF containers can have technically more than one package document but // like most reading systems we ' ll just use the first one .
func epubPackage(epub fs.FS) (string, error) {
	var ocf struct {
		XMLName  xml.Name `xml:"urn:oasis:names:tc:opendocument:xmlns:container container"`
		Version  string   `xml:"version,attr"`
		RootFile []struct {
			FullPath  string `xml:"full-path,attr"`
			MediaType string `xml:"media-type,attr"`
		} `xml:"urn:oasis:names:tc:opendocument:xmlns:container rootfiles>rootfile"`
	}
	f, err := epub.Open("META-INF/container.xml")
	if err != nil {
		return "", fmt.Errorf("parse OCF container: %w", err)
	}
	defer f.Close()
	if err := xml.NewDecoder(f).Decode(&ocf); err != nil {
		f.Close()
		return "", fmt.Errorf("parse OCF container: %w", err)
	}
	if ocf.Version != "1.0" {
		return "", fmt.Errorf("parse OCF container: invalid OCF version %q", ocf.Version)
	}
	for _, f := range ocf.RootFile {
		if f.MediaType == "application/oebps-package+xml" {
			return f.FullPath, nil
		}
	}
	return "", fmt.Errorf("parse OCF container: no valid package documents found")
}
func epubPackage ( epub fs . FS ) ( string , error ) { var ocf struct { XMLName xml . Name `xml:"urn:oasis:names:tc:opendocument:xmlns:container container"` Version string `xml:"version,attr"` RootFile [ ] struct { FullPath string `xml:"full-path,attr"` MediaType string `xml:"media-type,attr"` } `xml:"urn:oasis:names:tc:opendocument:xmlns:container rootfiles>rootfile"` } f , err := epub . Open ( " " ) if err != nil { return " " , fmt . Errorf ( " " , err ) } defer f . Close ( ) if err := xml . NewDecoder ( f ) . Decode ( & ocf ) ; err != nil { f . Close ( ) return " " , fmt . Errorf ( " " , err ) } if ocf . Version != " " { return " " , fmt . Errorf ( " " , ocf . Version ) } for _ , f := range ocf . RootFile { if f . MediaType == " " { return f . FullPath , nil } } return " " , fmt . Errorf ( " " ) }
epubPackage gets the filename of the first OPF package document from the OCF
container.
epubPackage gets the filename of the first OPF package document from the OCF container .
// we will be lenient about the mimetype file by not checking for it