use interface, not path

This commit is contained in:
Stephen McQuay 2016-12-10 15:41:31 -08:00
parent 30fae5b7ee
commit eb77956dc5
No known key found for this signature in database
GPG Key ID: 1ABF428F71BAFC3D

20
mov.go
View File

@ -4,24 +4,20 @@ import (
"bytes" "bytes"
"encoding/binary" "encoding/binary"
"errors" "errors"
"os" "io"
"time" "time"
) )
const epochAdjust = 2082844800 const epochAdjust = 2082844800
// Created attempts to find a created time from the metadata in a .mov file. // Created attempts to find a created time from the metadata in a .mov file.
func Created(path string) (time.Time, error) { func Created(file io.ReadSeeker) (time.Time, error) {
var r time.Time var r time.Time
f, err := os.Open(path) var err error
if err != nil {
return r, err
}
defer f.Close()
buf := [8]byte{} buf := [8]byte{}
for { for {
_, err := f.Read(buf[:]) _, err := file.Read(buf[:])
if err != nil { if err != nil {
return r, err return r, err
} }
@ -29,11 +25,11 @@ func Created(path string) (time.Time, error) {
break break
} else { } else {
atomSize := binary.BigEndian.Uint32(buf[:]) atomSize := binary.BigEndian.Uint32(buf[:])
f.Seek(int64(atomSize)-8, 1) file.Seek(int64(atomSize)-8, 1)
} }
} }
_, err = f.Read(buf[:]) _, err = file.Read(buf[:])
if err != nil { if err != nil {
return r, err return r, err
} }
@ -41,10 +37,10 @@ func Created(path string) (time.Time, error) {
s := string(buf[4:8]) s := string(buf[4:8])
switch s { switch s {
case "mvhd": case "mvhd":
if _, err := f.Seek(4, 1); err != nil { if _, err := file.Seek(4, 1); err != nil {
return r, err return r, err
} }
_, err = f.Read(buf[:4]) _, err = file.Read(buf[:4])
if err != nil { if err != nil {
return r, err return r, err
} }