~chrisppy/go-barefeed

5cc7bbea8771b9dbd936529d1220ba64eac7fd2d — Chris Palmer 18 days ago a45be83 main v0.4.1
file close fixes
3 files changed, 19 insertions(+), 10 deletions(-)

M barefeed.go
M message.go
M test-files/test.barefeed
M barefeed.go => barefeed.go +11 -4
@@ 19,13 19,20 @@ func FromFile(path string) (*Message, error) {
	if err != nil {
		return nil, err
	}
	defer func() {

	msg, err := FromReader(f)
	if err != nil {
		if err := f.Close(); err != nil {
			return
			return nil, err
		}
	}()
		return nil, err
	}

	if err := f.Close(); err != nil {
		return nil, err
	}

	return FromReader(f)
	return msg, nil
}

// FromReader will read barefeed from a Reader

M message.go => message.go +8 -6
@@ 30,20 30,22 @@ func (t Message) WriteFile(path string) error {
		return err
	}

	defer func() {
	w := bare.NewWriter(f)
	if w == nil {
		if err := f.Close(); err != nil {
			return
			return err
		}
	}()

	w := bare.NewWriter(f)
	if w == nil {
		return fmt.Errorf("writer is nil")
	}

	if err := bare.MarshalWriter(w, &t); err != nil {
		if err := f.Close(); err != nil {
			return err
		}

		return fmt.Errorf("unable to marshal message to file: %s", err.Error())
	}

	return nil
	return f.Close()
}

M test-files/test.barefeed => test-files/test.barefeed +0 -0