mirror of
https://github.com/h2non/filetype.git
synced 2025-12-24 11:52:08 +08:00
refactor: use filetype v1
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
1.0.0 / 2016-12-11
|
||||
==================
|
||||
|
||||
- First version.
|
||||
- Initial stable version (v1.0.0).
|
||||
|
||||
32
README.md
32
README.md
@@ -8,10 +8,10 @@ For SVG file type checking, see [go-is-svg](https://github.com/h2non/go-is-svg)
|
||||
|
||||
- Supports a [wide range](#supported-types) of file types
|
||||
- Provides file extension and proper MIME type
|
||||
- File discovery by extension or MIME type
|
||||
- File discovery by extension or MIME type
|
||||
- File discovery by class (image, video, audio...)
|
||||
- Provides a bunch of helpers and file matching shortcuts
|
||||
- [Pluggable](#add-additional-file-type-matchers): add custom new types and matchers
|
||||
- [Pluggable](#add-additional-file-type-matchers): add custom new types and matchers
|
||||
- Simple and semantic API
|
||||
- [Blazing fast](#benchmarks), even processing large files
|
||||
- Only first 261 bytes representing the max file header is required, so you can just [pass a slice](#file-header)
|
||||
@@ -21,7 +21,7 @@ For SVG file type checking, see [go-is-svg](https://github.com/h2non/go-is-svg)
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
go get gopkg.in/h2non/filetype.v0
|
||||
go get gopkg.in/h2non/filetype.v1
|
||||
```
|
||||
|
||||
## API
|
||||
@@ -30,19 +30,19 @@ See [Godoc](https://godoc.org/github.com/h2non/filetype) reference.
|
||||
|
||||
### Subpackages
|
||||
|
||||
- [`gopkg.in/h2non/filetype.v0/types`](https://godoc.org/github.com/h2non/filetype/types)
|
||||
- [`gopkg.in/h2non/filetype.v0/matchers`](https://godoc.org/github.com/h2non/filetype/matchers)
|
||||
- [`gopkg.in/h2non/filetype.v1/types`](https://godoc.org/github.com/h2non/filetype/types)
|
||||
- [`gopkg.in/h2non/filetype.v1/matchers`](https://godoc.org/github.com/h2non/filetype/matchers)
|
||||
|
||||
## Examples
|
||||
|
||||
#### Simple file type checking
|
||||
|
||||
```go
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gopkg.in/h2non/filetype.v0"
|
||||
"gopkg.in/h2non/filetype.v1"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
@@ -61,12 +61,12 @@ func main() {
|
||||
|
||||
#### Check type class
|
||||
|
||||
```go
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gopkg.in/h2non/filetype.v0"
|
||||
"gopkg.in/h2non/filetype.v1"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
@@ -83,12 +83,12 @@ func main() {
|
||||
|
||||
#### Supported type
|
||||
|
||||
```go
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gopkg.in/h2non/filetype.v0"
|
||||
"gopkg.in/h2non/filetype.v1"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -115,7 +115,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gopkg.in/h2non/filetype.v0"
|
||||
"gopkg.in/h2non/filetype.v1"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
@@ -132,16 +132,16 @@ func main() {
|
||||
fmt.Println("Not an image")
|
||||
}
|
||||
}
|
||||
```
|
||||
```
|
||||
|
||||
#### Add additional file type matchers
|
||||
|
||||
```go
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gopkg.in/h2non/filetype.v0"
|
||||
"gopkg.in/h2non/filetype.v1"
|
||||
)
|
||||
|
||||
var fooType = filetype.NewType("foo", "foo/foo")
|
||||
@@ -246,7 +246,7 @@ func main() {
|
||||
|
||||
## Benchmarks
|
||||
|
||||
Measured using [real files](https://github.com/h2non/filetype/tree/master/fixtures).
|
||||
Measured using [real files](https://github.com/h2non/filetype/tree/master/fixtures).
|
||||
|
||||
Environment: OSX x64 i7 2.7 Ghz
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ package filetype
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"gopkg.in/h2non/filetype.v0/matchers"
|
||||
"gopkg.in/h2non/filetype.v0/types"
|
||||
"gopkg.in/h2non/filetype.v1/matchers"
|
||||
"gopkg.in/h2non/filetype.v1/types"
|
||||
)
|
||||
|
||||
// Map of supported types
|
||||
|
||||
@@ -3,7 +3,7 @@ package filetype
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gopkg.in/h2non/filetype.v0/types"
|
||||
"gopkg.in/h2non/filetype.v1/types"
|
||||
)
|
||||
|
||||
func TestIs(t *testing.T) {
|
||||
|
||||
4
kind.go
4
kind.go
@@ -1,8 +1,8 @@
|
||||
package filetype
|
||||
|
||||
import (
|
||||
"gopkg.in/h2non/filetype.v0/matchers"
|
||||
"gopkg.in/h2non/filetype.v0/types"
|
||||
"gopkg.in/h2non/filetype.v1/matchers"
|
||||
"gopkg.in/h2non/filetype.v1/types"
|
||||
)
|
||||
|
||||
// Image tries to match a file as image type
|
||||
|
||||
4
match.go
4
match.go
@@ -4,8 +4,8 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"gopkg.in/h2non/filetype.v0/matchers"
|
||||
"gopkg.in/h2non/filetype.v0/types"
|
||||
"gopkg.in/h2non/filetype.v1/matchers"
|
||||
"gopkg.in/h2non/filetype.v1/types"
|
||||
)
|
||||
|
||||
// Map of registered file matchers
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
|
||||
"gopkg.in/h2non/filetype.v0/matchers"
|
||||
"gopkg.in/h2non/filetype.v0/types"
|
||||
"gopkg.in/h2non/filetype.v1/matchers"
|
||||
"gopkg.in/h2non/filetype.v1/types"
|
||||
)
|
||||
|
||||
func TestMatch(t *testing.T) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package matchers
|
||||
|
||||
import "gopkg.in/h2non/filetype.v0/types"
|
||||
import "gopkg.in/h2non/filetype.v1/types"
|
||||
|
||||
// Internal shortcut to NewType
|
||||
var newType = types.NewType
|
||||
|
||||
Reference in New Issue
Block a user