Skip to content

Commit

Permalink
🌹 Add fileTypePromise to usage
Browse files Browse the repository at this point in the history
  • Loading branch information
LinusU committed Jan 25, 2017
1 parent b38ab84 commit e583d30
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const FileType = require('stream-file-type')
const input = fs.createReadStream('cat.jpg')
const detector = new FileType()

// Listen for event...
detector.on('file-type', (fileType) => {
if (fileType === null) {
console.log(`The mime type of "cat.jpg" could not be determined`)
Expand All @@ -19,6 +20,15 @@ detector.on('file-type', (fileType) => {
}
})

// ...or get a Promise
detector.fileTypePromise().then((fileType) => {
if (fileType === null) {
console.log(`The mime type of "cat.jpg" could not be determined`)
} else {
console.log(`The file "cat.jpg" has the "${fileType.mime}" mime type`)
}
})

input.pipe(detector).resume()
```

Expand Down

0 comments on commit e583d30

Please sign in to comment.