Skip to content

Commit

Permalink
code org
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq committed May 12, 2023
1 parent 05cba9f commit b670b4a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
13 changes: 1 addition & 12 deletions internal/chunk/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ func (idx index) OffsetCount() int {
return n
}

// offsets holds the index of the current offset in the index for each chunk
// ID.
type offsets map[GroupID]int

// FromReader creates a new chunk File from the io.ReadSeeker.
func FromReader(rs io.ReadSeeker) (*File, error) {
if _, err := rs.Seek(0, io.SeekStart); err != nil { // reset offset
Expand Down Expand Up @@ -149,18 +145,11 @@ func (f *File) ForEach(fn func(ev *Chunk) error) error {
return nil
}

// namer is an interface that allows us to get the name of the file.
type namer interface {
// Name should return the name of the file. *os.File implements this
// interface.
Name() string
}

// State generates and returns the state of the file. It does not include
// the path to the downloaded files.
func (f *File) State() (*state.State, error) {
var name string
if file, ok := f.rs.(namer); ok {
if file, ok := f.rs.(state.Namer); ok {
name = filepath.Base(file.Name())
}
s := state.New(name)
Expand Down
4 changes: 4 additions & 0 deletions internal/chunk/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (

var ErrExhausted = errors.New("exhausted")

// offsets holds the index of the current offset in the index for each chunk
// ID.
type offsets map[GroupID]int

// Player replays the chunks from a file, it is able to emulate the API
// responses, if used in conjunction with the [proctest.Server]. Zero value is
// not usable.
Expand Down
2 changes: 1 addition & 1 deletion internal/chunk/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func WithEncoder(enc Encoder) Option {

func NewRecorder(w io.Writer, options ...Option) *Recorder {
filename := "unknown"
if f, ok := w.(namer); ok {
if f, ok := w.(state.Namer); ok {
filename = f.Name()
}
rec := &Recorder{
Expand Down
7 changes: 7 additions & 0 deletions internal/chunk/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ type Stater interface {
State() (*State, error)
}

// Namer is an interface that allows us to get the name of the file.
type Namer interface {
// Name should return the name of the file. *os.File implements this
// interface.
Name() string
}

// New returns a new State.
func New(filename string) *State {
return &State{
Expand Down

0 comments on commit b670b4a

Please sign in to comment.