Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Change Parse method to accept io.Reader instead of []byte#14

Merged
xcapaldi merged 1 commit into
mainfrom
claude/parser-reader-interface-q9T54
Mar 16, 2026
Merged

Change Parse method to accept io.Reader instead of []byte#14
xcapaldi merged 1 commit into
mainfrom
claude/parser-reader-interface-q9T54

Conversation

@xcapaldi
Copy link
Copy Markdown
Owner

Summary

This change modifies the Parser.Parse() method signature to accept an io.Reader instead of a byte slice, improving flexibility and reducing memory overhead for large files.

Key Changes

  • Parser.Parse() signature: Changed from Parse(source []byte) to Parse(r io.Reader) to accept any reader implementation
  • Internal implementation: Added io.ReadAll() call within Parse to convert the reader to bytes for processing
  • Example programs: Updated examples/parse, examples/flatten, and examples/scale to use os.Open() and pass file handles directly instead of reading entire files into memory with os.ReadFile()
  • Test updates: Updated all test files to wrap byte slices with bytes.NewReader() when calling Parse
  • Recursive parsing: Updated internal resolveLinkedRecipe() to wrap file data with bytes.NewReader() when recursively parsing linked recipes

Benefits

  • More idiomatic Go API that works with any reader (files, buffers, network streams, etc.)
  • Potential memory efficiency improvements for large files in streaming scenarios
  • Better separation of concerns between I/O and parsing logic

https://claude.ai/code/session_01U634BP9mJy46WX8oNtJHnr

Accepting io.Reader is idiomatic Go for byte-stream consumption.
Callers can now pass *os.File, http.Response.Body, strings.NewReader,
etc. directly. Internally io.ReadAll buffers the bytes for goldmark,
which is identical overhead to what callers did before with os.ReadFile.
@xcapaldi xcapaldi force-pushed the claude/parser-reader-interface-q9T54 branch from 48e4990 to 33beee6 Compare March 16, 2026 20:50
@xcapaldi xcapaldi merged commit af19e84 into main Mar 16, 2026
@xcapaldi xcapaldi deleted the claude/parser-reader-interface-q9T54 branch March 17, 2026 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants