Skip to content

Commit

Permalink
Output {file} 'type' alongside encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
ross-spencer committed May 27, 2018
1 parent 5c6e72c commit 60671ae
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ Created for Artefactual Systems Inc.
Guess filename encodings... based on @richardlehane's [characterize][char]
golang package.

## Usage
```
ross-spencer@artefactual:~:$ fndec -h
Usage of fndec:
-file string
File to read the filename from.
-version
Return version information.
```
## Example output
![alt text][example-one]

Expand Down
Binary file modified docs/images/example-output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 25 additions & 3 deletions fndec.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"path/filepath"
)

const version = "fndec-0.0.2"
const version = "fndec-0.0.3"

var (
file string
Expand All @@ -20,9 +20,31 @@ func init() {
flag.BoolVar(&vers, "version", false, "Return version information.")
}

// Crimped from, https://github.com/richardlehane/siegfried/blob/a3cf617aaec3206f894ac488ae2c5ce1ac2f4230/cmd/sf/sf.go#L82-L101
func ftype(mode os.FileMode) string {
typ := "unknown"
switch {
case mode&os.ModeType == 0:
typ = "regular file"
case mode&os.ModeDir == os.ModeDir:
typ = "directory"
case mode&os.ModeSymlink == os.ModeSymlink:
typ = "symlink"
case mode&os.ModeNamedPipe == os.ModeNamedPipe:
typ = "named pipe"
case mode&os.ModeSocket == os.ModeSocket:
typ = "socket"
case mode&os.ModeDevice == os.ModeDevice:
typ = "device"
}
return typ
}

func readFileName(path string, fi os.FileInfo, err error) error {
fmt.Printf("Character encoding for fname: '%s' detected: %s\n",
filepath.Base(path), char.Detect([]byte(filepath.Base(path))))
fmt.Printf("Character encoding for '%s' name: '%s' detected: %s\n",
ftype(fi.Mode()),
filepath.Base(path),
char.Detect([]byte(filepath.Base(path))))
return nil
}

Expand Down
Empty file added tests/fixtures/symlink/regular
Empty file.
1 change: 1 addition & 0 deletions tests/fixtures/symlink/symlink_to_regular

0 comments on commit 60671ae

Please sign in to comment.