Node.jsでパスがバイナリファイルのパスであるかチェックする
パスがバイナリファイルのパスであるかチェックするにはis-binary-path
モジュールのisBinaryPath
関数を使用します。
var isBinaryPath = require('is-binary-path');
var isBinary = isBinaryPath('xxx');
第1引数にパスを指定します。
返り値としてパスがバイナリファイルのパスであるかが真偽値として得られます。
サンプルコード1
is-binary-path.js
var isBinaryPath = require('is-binary-path');
console.log(isBinaryPath('image.png'));
console.log(isBinaryPath('text.txt'));
console.log(isBinaryPath('C:\work\node\image.png'));
console.log(isBinaryPath('C:\work\node\text.txt'));
使用パッケージ
- is-binary-path
npm install is-binary-path
でインストールします。
実行結果
C:\work\node>node is-binary-path.js
true
false
true
false
関連

スポンサーリンク