Renamed listenbrainz.Archive to listenbrainz.ExportArchive

This commit is contained in:
Philipp Wolfer 2025-05-24 00:51:28 +02:00
parent 8462b9395e
commit cf5319309a
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
2 changed files with 8 additions and 8 deletions

View file

@ -69,7 +69,7 @@ func (b *ListenBrainzArchiveBackend) ExportListens(
}, },
} }
archive, err := listenbrainz.OpenArchive(b.filePath) archive, err := listenbrainz.OpenExportArchive(b.filePath)
if err != nil { if err != nil {
p.Export.Abort() p.Export.Abort()
progress <- p progress <- p

View file

@ -38,27 +38,27 @@ import (
// //
// The export contains the user's listen history, favorite tracks and // The export contains the user's listen history, favorite tracks and
// user information. // user information.
type Archive struct { type ExportArchive struct {
backend archive.Archive backend archive.Archive
} }
// Open a ListenBrainz archive from file path. // Open a ListenBrainz archive from file path.
func OpenArchive(path string) (*Archive, error) { func OpenExportArchive(path string) (*ExportArchive, error) {
backend, err := archive.OpenArchive(path) backend, err := archive.OpenArchive(path)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &Archive{backend: backend}, nil return &ExportArchive{backend: backend}, nil
} }
// Close the archive and release any resources. // Close the archive and release any resources.
func (a *Archive) Close() error { func (a *ExportArchive) Close() error {
return a.backend.Close() return a.backend.Close()
} }
// Read the user information from the archive. // Read the user information from the archive.
func (a *Archive) UserInfo() (UserInfo, error) { func (a *ExportArchive) UserInfo() (UserInfo, error) {
f, err := a.backend.OpenFile("user.json") f, err := a.backend.OpenFile("user.json")
if err != nil { if err != nil {
return UserInfo{}, err return UserInfo{}, err
@ -75,7 +75,7 @@ func (a *Archive) UserInfo() (UserInfo, error) {
return userInfo, nil return userInfo, nil
} }
func (a *Archive) ListListenExports() ([]ListenExportFileInfo, error) { func (a *ExportArchive) ListListenExports() ([]ListenExportFileInfo, error) {
re := regexp.MustCompile(`^listens/(\d{4})/(\d{1,2})\.jsonl$`) re := regexp.MustCompile(`^listens/(\d{4})/(\d{1,2})\.jsonl$`)
result := make([]ListenExportFileInfo, 0) result := make([]ListenExportFileInfo, 0)
@ -109,7 +109,7 @@ func (a *Archive) ListListenExports() ([]ListenExportFileInfo, error) {
// Yields all listens from the archive that are newer than the given timestamp. // Yields all listens from the archive that are newer than the given timestamp.
// The listens are yielded in ascending order of their listened_at timestamp. // The listens are yielded in ascending order of their listened_at timestamp.
func (a *Archive) IterListens(minTimestamp time.Time) iter.Seq2[Listen, error] { func (a *ExportArchive) IterListens(minTimestamp time.Time) iter.Seq2[Listen, error] {
return func(yield func(Listen, error) bool) { return func(yield func(Listen, error) bool) {
files, err := a.ListListenExports() files, err := a.ListListenExports()
if err != nil { if err != nil {