@d-zero/filematch
v1.1.0
Published
A simple file matching library
Readme
@d-zero/filematch
2つのファイルパスもしくはURLを渡して、そのファイルの内容を比較するツールです。単純に差異があるかどうかしか判定しません。差分検出ではないことに注意してください。
このツールの用途としては、例えば以下のようなものが考えられます。
- リダイレクト処理のテスト
- アップロード・デプロイの成功の判定
バイト単位で比較を行うため、ファイルの種類に関係なく比較が可能です。また、そのため画像は圧縮率が異なれば異なるファイルとして判定されます。
使い方
ファイル比較
オプション
npx @d-zero/filematch <file_path_or_url_1> <file_path_or_url_2>例
npx @d-zero/filematch ./test1.pdf ./test2.pdfnpx @d-zero/filematch https://example.com/test1.pdf https://example.com/test2.pdfローカルファイルとURLを混在して比較することも可能です。
npx @d-zero/filematch ./test1.pdf https://example.com/test2.pdfリストファイルからの比較
-fオプションを使用することで、リストファイルからの比較が可能です。
npx @d-zero/filematch -f <list_file_path>./test1.pdf ./test2.pdf
https://example.com/test1.pdf https://example.com/test2.pdf
https://example.com/test1.png https://example.com/test2.png
https://example.com/test1.html https://example.com/test2.html
https://example.com/test1.js https://example.com/test2.jsnpx @d-zero/filematch -f list.txtAPI
このパッケージはAPIとしても使用できます。
基本的な使い方
import { compare } from '@d-zero/filematch';
// 2つのファイルパスまたはURLを比較
const result = await compare('./test1.pdf', './test2.pdf');
console.log(result); // true または false進捗の監視
import { compare } from '@d-zero/filematch';
const result = await compare('./test1.pdf', './test2.pdf', (progress) => {
// progress は 0.0 から 1.0 の間の値
console.log(`進捗: ${(progress * 100).toFixed(2)}%`);
});型定義
import type { OnProgress } from '@d-zero/filematch';
const onProgress: OnProgress = (progress) => {
console.log(`進捗: ${progress}`);
};動作環境
- Node.js 20.11以降
