Here is the full (trimmed) working program:

// Exif project Exif.go 

package main


import (

    //"bytes"

    "encoding/binary"

    "fmt"

    "os"

)


const JPEGSOIMarker = 0xffd8

const APPMarkerBegin = 0xffe1

const APPMarkerEnd = 0xffef

const ExifEncoding = "II"


type Header struct {

    Exif_SOI     uint16

    APPMarkerTag uint16

    MarkerSize   uint16

    ExifTxt      [6]byte

    ExifEncoding [2]byte

    TagMark      uint16

    OffsetIDF    [4]byte

}


func isJpgImage(header Header) bool {

    return header.Exif_SOI == JPEGSOIMarker

}


func isAPPn(header Header) bool {

    return header.APPMarkerTag == APPMarkerBegin

}


func readFile(filename string) error {

    header := Header{}

    in, err := os.Open(filename)

    defer func() { in.Close() }()

    if err != nil {

        return err

    }

    binary.Read(in, binary.BigEndian, &header)

    fmt.Printf("is valid Jpg format: %t\n", isJpgImage(header))

    if isJpgImage(header) {

        fmt.Printf("%X\n", header.Exif_SOI)

        if isAPPn(header) {

            fmt.Printf("%X\n", header.APPMarkerTag)

            fmt.Printf("Exif %s\n", string(header.ExifTxt[:4]))

            fmt.Printf("Intel Encoding %t\n", string(header.ExifEncoding[:2]) 
== ExifEncoding)

        }

    }

    return nil

}


func main() {

    readFile("image.JPG")

}





On Thursday, October 5, 2017 at 8:11:25 PM UTC+2, Ian Davis wrote:
>
>
> On Thu, 5 Oct 2017, at 08:58 AM, Johan terryn wrote:
>
> In following code:
>
>
> type JPGFile struct {
>
>     Exif_SOI [2]byte
>
>     Exif
>
> }
> type Exif struct {    APP1Marker   [2]byte    APP1DataSize uint16    
> ExifHeader   [6]byte    TIFFHeader[6]byte}
>
> func ReadFile(filename string) (JPGFile, error) {
>
>     jpgFile := JPGFile{}
>
>     in, err := os.Open(filename)
>
>     defer in.Close()
>
>     if err != nil {
>
>         return jpgFile, err
>
>     }
>
>     binary.Read(in, binary.LittleEndian, &jpgFile)
>
>         return jpgFile, nil 
>
> }
>
>
>
>
> *binary.Read* accepts "in" (os.File) as a reader, but if I pass the file 
> as a parameter to the function I get the (correct ) error message that "in" 
> is not a reader, as defined in the documentation: func Read(r *io.Reader*, 
> order ByteOrder, data interface{}) error
>
>
> Or is this working as intended?
>
>
> Can you provide a fuller example showing imports? Your code looks correct 
> and "in" is an io.Reader so it's surprising that you are getting that 
> message. This non-runnable version of your code compiles fine: 
> https://play.golang.org/p/aruCeIHFEZ 
>
>
> Ian
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to