Add a GIF mime type, TODOs, add camdebug mime command.

Change-Id: Ic8930d4250dec30ed8c9a056c1cecd70cc447f9d
This commit is contained in:
Brad Fitzpatrick 2012-12-06 17:53:03 -08:00
parent 31df4a7a01
commit 682390dffa
4 changed files with 49 additions and 5 deletions

View File

@ -18,18 +18,22 @@ package main
import ( import (
"flag" "flag"
"log"
) )
var flagSplits = flag.Bool("splits", false, "show splits") var (
flagSplits = flag.Bool("splits", false, "show splits of provided filename")
flagMIME = flag.Bool("mime", false, "show MIME type of provided file")
)
func main() { func main() {
flag.Parse() flag.Parse()
if *flagMIME {
showMIME()
return
}
if *flagSplits { if *flagSplits {
showSplits() showSplits()
return return
} }
flag.Usage()
log.Fatalf("TODO: usage info")
} }

36
cmd/camdebug/mime.go Normal file
View File

@ -0,0 +1,36 @@
/*
Copyright 2012 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"flag"
"log"
"fmt"
"os"
"camlistore.org/pkg/magic"
)
func showMIME() {
file := flag.Arg(0)
f, err := os.Open(file)
if err != nil {
log.Fatal(err)
}
mime, _ := magic.MimeTypeFromReader(f)
fmt.Println(mime)
}

View File

@ -94,4 +94,5 @@ func showSplits() {
} }
} }
dumpSpans(spans, 0) dumpSpans(spans, 0)
fmt.Printf("\n\nNOTE NOTE NOTE: the camdebug tool hasn't been updated to use the splitting policy from pkg/schema/filewriter.go.")
} }

View File

@ -29,12 +29,15 @@ type prefixEntry struct {
} }
var prefixTable = []prefixEntry{ var prefixTable = []prefixEntry{
{[]byte("GIF87a"), "image/gif"},
{[]byte("GIF89a"), "image/gif"}, // TODO: Others?
{[]byte("\xff\xd8\xff\xe2"), "image/jpeg"}, {[]byte("\xff\xd8\xff\xe2"), "image/jpeg"},
{[]byte("\xff\xd8\xff\xe1"), "image/jpeg"}, {[]byte("\xff\xd8\xff\xe1"), "image/jpeg"},
{[]byte("\xff\xd8\xff\xe0"), "image/jpeg"}, {[]byte("\xff\xd8\xff\xe0"), "image/jpeg"},
{[]byte("\xff\xd8\xff\xdb"), "image/jpeg"}, {[]byte("\xff\xd8\xff\xdb"), "image/jpeg"},
{[]byte{137, 'P', 'N', 'G', '\r', '\n', 26, 10}, "image/png"}, {[]byte{137, 'P', 'N', 'G', '\r', '\n', 26, 10}, "image/png"},
{[]byte("-----BEGIN PGP PUBLIC KEY BLOCK---"), "text/x-openpgp-public-key"}, {[]byte("-----BEGIN PGP PUBLIC KEY BLOCK---"), "text/x-openpgp-public-key"},
// TODO(bradfitz): popular audio & video formats at least
} }
// Returns the emptry string if unknown. // Returns the emptry string if unknown.