mirror of
https://github.com/dsoprea/go-exif.git
synced 2025-05-31 11:41:57 +00:00
Given a stream of data, it is possible to determine the beginning of EXIF data but not the end. Therefore, either an image-aware implementation must know how to parse an image and extract the EXIF data or a brute-force search implementation (one of which is provided by this project) must find the start anchor and then return all bytes from that to the end of the file. We have been made aware of some use-cases where a brute-force search might be unavoidable due to trust or stability issues with the image structure. This leads to large allocations. This can be avoided by accomodating support that will allow for both a byte-slice or an `io.ReadSeeker`. Since the EXIF structure is typically not read- intensive (a couple of kilobytes if no thumbnail is present), this should have a minimal performance impact. Closes #42
76 lines
1.6 KiB
Go
76 lines
1.6 KiB
Go
package exifundefined
|
|
|
|
import (
|
|
"bytes"
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/dsoprea/go-logging"
|
|
"github.com/dsoprea/go-utility/filesystem"
|
|
|
|
"github.com/dsoprea/go-exif/v2/common"
|
|
)
|
|
|
|
func TestTag927CMakerNote_String(t *testing.T) {
|
|
ut := Tag927CMakerNote{
|
|
MakerNoteType: []byte{0, 1, 2, 3, 4},
|
|
MakerNoteBytes: []byte{5, 6, 7, 8, 9},
|
|
}
|
|
|
|
s := ut.String()
|
|
if s != "MakerNote<TYPE-ID=[00 01 02 03 04] LEN=(5) SHA1=[bdb42cb7eb76e64efe49b22369b404c67b0af55a]>" {
|
|
t.Fatalf("String not correct: [%s]", s)
|
|
}
|
|
}
|
|
|
|
func TestCodec927CMakerNote_Encode(t *testing.T) {
|
|
codec := Codec927CMakerNote{}
|
|
|
|
prefix := []byte{0, 1, 2, 3, 4}
|
|
b := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
|
|
|
|
ut := Tag927CMakerNote{
|
|
MakerNoteType: prefix,
|
|
MakerNoteBytes: b,
|
|
}
|
|
|
|
encoded, unitCount, err := codec.Encode(ut, exifcommon.TestDefaultByteOrder)
|
|
log.PanicIf(err)
|
|
|
|
if bytes.Equal(encoded, b) != true {
|
|
t.Fatalf("Encoding not correct: %v", encoded)
|
|
} else if unitCount != uint32(len(b)) {
|
|
t.Fatalf("Unit-count not correct: (%d)", len(b))
|
|
}
|
|
}
|
|
|
|
func TestCodec927CMakerNote_Decode(t *testing.T) {
|
|
b := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
|
|
|
|
ut := Tag927CMakerNote{
|
|
MakerNoteType: b,
|
|
MakerNoteBytes: b,
|
|
}
|
|
|
|
sb := rifs.NewSeekableBufferWithBytes(b)
|
|
|
|
valueContext := exifcommon.NewValueContext(
|
|
"",
|
|
0,
|
|
uint32(len(b)),
|
|
0,
|
|
nil,
|
|
sb,
|
|
exifcommon.TypeUndefined,
|
|
exifcommon.TestDefaultByteOrder)
|
|
|
|
codec := Codec927CMakerNote{}
|
|
|
|
value, err := codec.Decode(valueContext)
|
|
log.PanicIf(err)
|
|
|
|
if reflect.DeepEqual(value, ut) != true {
|
|
t.Fatalf("Decoded value not correct: %s != %s", value, ut)
|
|
}
|
|
}
|