zeroshade commented on code in PR #216:
URL: https://github.com/apache/arrow-go/pull/216#discussion_r1887304246
##########
arrow/ipc/file_reader.go:
##########
@@ -33,16 +33,166 @@ import (
"github.com/apache/arrow-go/v18/arrow/memory"
)
-// FileReader is an Arrow file reader.
-type FileReader struct {
+type readerImpl interface {
+ getFooterEnd() (int64, error)
+ readFooter(*footerBlock) error
+ dict(memory.Allocator, *footerBlock, int) (dataBlock, error)
+ block(memory.Allocator, *footerBlock, int) (dataBlock, error)
+}
+
+type footerBlock struct {
+ offset int64
+ buffer *memory.Buffer
+ data *flatbuf.Footer
+}
+
+type dataBlock interface {
+ Offset() int64
+ Meta() int32
+ Body() int64
+ NewMessage() (*Message, error)
+}
+
+type basicReaderImpl struct {
r ReadAtSeeker
+}
- footer struct {
- offset int64
- buffer *memory.Buffer
- data *flatbuf.Footer
+func (r *basicReaderImpl) getFooterEnd() (int64, error) {
+ return r.r.Seek(0, io.SeekEnd)
+}
+
+func (r *basicReaderImpl) readFooter(f *footerBlock) error {
+ var err error
+
+ if f.offset <= int64(len(Magic)*2+4) {
+ return fmt.Errorf("arrow/ipc: file too small (size=%d)",
f.offset)
+ }
+
+ eof := int64(len(Magic) + 4)
+ buf := make([]byte, eof)
+ n, err := r.r.ReadAt(buf, f.offset-eof)
+ if err != nil {
+ return fmt.Errorf("arrow/ipc: could not read footer: %w", err)
+ }
+ if n != len(buf) {
+ return fmt.Errorf("arrow/ipc: could not read %d bytes from end
of file", len(buf))
+ }
+
+ if !bytes.Equal(buf[4:], Magic) {
+ return errNotArrowFile
+ }
+
+ size := int64(binary.LittleEndian.Uint32(buf[:4]))
Review Comment:
@lidavidm is correct, only the unsigned versions are available and you are
expected to convert to signed integer yourself if you need.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]