Skip to content

Commit

Permalink
Remove period from file extension (#1154)
Browse files Browse the repository at this point in the history
* Remove period from file extension.

* Add comment.
  • Loading branch information
ahrav authored Mar 6, 2023
1 parent e6846ed commit 5c99a1e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/common/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ package common

import (
"path/filepath"
"strings"
)

var (
KB, MB, GB, TB, PB = 1e3, 1e6, 1e9, 1e12, 1e15
IGNORED_EXTENSIONS = []string{"mp4", "avi", "mpeg", "mpg", "mov", "wmv", "m4p", "swf", "mp2", "flv", "vob", "webm", "hdv", "3gp", "ogg", "mp3", "wav", "flac", "webp"}
IgnoredExtensions = []string{"mp4", "avi", "mpeg", "mpg", "mov", "wmv", "m4p", "swf", "mp2", "flv", "vob", "webm", "hdv", "3gp", "ogg", "mp3", "wav", "flac", "webp"}
)

func SkipFile(filename string) bool {
for _, ext := range IGNORED_EXTENSIONS {
if filepath.Ext(filename) == ext {
for _, ext := range IgnoredExtensions {
if strings.TrimPrefix(filepath.Ext(filename), ".") == ext {
return true
}
}
Expand Down
36 changes: 36 additions & 0 deletions pkg/common/vars_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package common

import "testing"

func TestSkipFile(t *testing.T) {
type testCase struct {
file string
want bool
}

// Add a test case for each ignored extension.
testCases := make([]testCase, 0, len(IgnoredExtensions)+1)
for _, ext := range IgnoredExtensions {
testCases = append(testCases, testCase{
file: "test." + ext,
want: true,
})
}

// Add a test case for a file that should not be skipped.
testCases = append(testCases, testCase{file: "test.txt", want: false})

for _, tt := range testCases {
t.Run(tt.file, func(t *testing.T) {
if got := SkipFile(tt.file); got != tt.want {
t.Errorf("SkipFile(%v) got %v, want %v", tt.file, got, tt.want)
}
})
}
}

func BenchmarkSkipFile(b *testing.B) {
for i := 0; i < b.N; i++ {
SkipFile("test.mp4")
}
}

0 comments on commit 5c99a1e

Please sign in to comment.