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"
"encoding/binary"
"errors"
"os"
"io"
"time"
)
const epochAdjust = 2082844800
// 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
f, err := os.Open(path)
if err != nil {
return r, err
}
defer f.Close()
var err error
buf := [8]byte{}
for {
_, err := f.Read(buf[:])
_, err := file.Read(buf[:])
if err != nil {
return r, err
}
@ -29,11 +25,11 @@ func Created(path string) (time.Time, error) {
break
} else {
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 {
return r, err
}
@ -41,10 +37,10 @@ func Created(path string) (time.Time, error) {
s := string(buf[4:8])
switch s {
case "mvhd":
if _, err := f.Seek(4, 1); err != nil {
if _, err := file.Seek(4, 1); err != nil {
return r, err
}
_, err = f.Read(buf[:4])
_, err = file.Read(buf[:4])
if err != nil {
return r, err
}