gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

data_layer.go (1161B)


      1 package exif
      2 
      3 import (
      4 	"io"
      5 
      6 	"github.com/dsoprea/go-logging"
      7 	"github.com/dsoprea/go-utility/v2/filesystem"
      8 )
      9 
     10 type ExifBlobSeeker interface {
     11 	GetReadSeeker(initialOffset int64) (rs io.ReadSeeker, err error)
     12 }
     13 
     14 // ExifReadSeeker knows how to retrieve data from the EXIF blob relative to the
     15 // beginning of the blob (so, absolute position (0) is the first byte of the
     16 // EXIF data).
     17 type ExifReadSeeker struct {
     18 	rs io.ReadSeeker
     19 }
     20 
     21 func NewExifReadSeeker(rs io.ReadSeeker) *ExifReadSeeker {
     22 	return &ExifReadSeeker{
     23 		rs: rs,
     24 	}
     25 }
     26 
     27 func NewExifReadSeekerWithBytes(exifData []byte) *ExifReadSeeker {
     28 	sb := rifs.NewSeekableBufferWithBytes(exifData)
     29 	edbs := NewExifReadSeeker(sb)
     30 
     31 	return edbs
     32 }
     33 
     34 // Fork creates a new ReadSeeker instead that wraps a BouncebackReader to
     35 // maintain its own position in the stream.
     36 func (edbs *ExifReadSeeker) GetReadSeeker(initialOffset int64) (rs io.ReadSeeker, err error) {
     37 	defer func() {
     38 		if state := recover(); state != nil {
     39 			err = log.Wrap(state.(error))
     40 		}
     41 	}()
     42 
     43 	br, err := rifs.NewBouncebackReader(edbs.rs)
     44 	log.PanicIf(err)
     45 
     46 	_, err = br.Seek(initialOffset, io.SeekStart)
     47 	log.PanicIf(err)
     48 
     49 	return br, nil
     50 }