Skip to content

Commit

Permalink
ctx comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ungerik committed May 16, 2024
1 parent 2afba6b commit 7cb7200
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions memfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,20 @@ func (f MemFile) OpenReadSeeker() (ReadSeekCloser, error) {

// ReadJSON reads and unmarshalles the JSON content of the file to output.
func (f MemFile) ReadJSON(ctx context.Context, output any) error {
if ctx.Err() != nil {
return ctx.Err()
// Context is passed for identical call signature as other types
if err := ctx.Err(); err != nil {
return err
}
return json.Unmarshal(f.FileData, output)
}

// WriteJSON mashalles input to JSON and writes it as the file.
// Any indent arguments will be concanated and used as JSON line indentation.
func (f *MemFile) WriteJSON(ctx context.Context, input any, indent ...string) (err error) {
// Context is passed for identical call signature as other types
if err = ctx.Err(); err != nil {
return err
}
var data []byte
if len(indent) == 0 {
data, err = json.Marshal(input)
Expand All @@ -269,15 +274,20 @@ func (f *MemFile) WriteJSON(ctx context.Context, input any, indent ...string) (e

// ReadXML reads and unmarshalles the XML content of the file to output.
func (f MemFile) ReadXML(ctx context.Context, output any) error {
if ctx.Err() != nil {
return ctx.Err()
// Context is passed for identical call signature as other types
if err := ctx.Err(); err != nil {
return err
}
return xml.Unmarshal(f.FileData, output)
}

// WriteXML mashalles input to XML and writes it as the file.
// Any indent arguments will be concanated and used as XML line indentation.
func (f *MemFile) WriteXML(ctx context.Context, input any, indent ...string) (err error) {
// Context is passed for identical call signature as other types
if err = ctx.Err(); err != nil {
return err
}
var data []byte
if len(indent) == 0 {
data, err = xml.Marshal(input)
Expand Down

0 comments on commit 7cb7200

Please sign in to comment.