FolderBsdp algorithm utilizes bsdp algorithm and file operations to provides diffing and patching capacities for two folders
npm install folderbsdpThis package supports ESM and CommonJS. We use ESM here as the example.
sh
npm install folderbsdp --save
`
Use API
`typescript
import FolderBsdp from "FolderBsdp"
FolderBsdp.diff("./Users/myname/Documents/Afolder", "./Users/myname/Documents/Bfolder", "./Users/myname/Documents/ABdifference.patch")
FolderBsdp.patch("./Users/myname/Documents/Afolder", "./Users/myname/Documents/Bfolder", "./Users/myname/Documents/ABdifference.patch")
`Explanation of API
`typescript
FolderBsdp.diff("./Users/myname/Documents/Afolder", "./Users/myname/Documents/Bfolder", "./Users/myname/Documents/ABdifference.patch")
`In the code above, it lists A folder's directory and B folder's directory as the resources, the patch result will be written to path "./Users/myname/Documents/" with file name "ABdifference.patch". Please make sure that "./Users/myname/Documents/ABdifference.patch" does not exist beforehand. Otherwise, the original file will be replaced. The patch file can use any suffix different from ".patch". The execution returns a promise, which carries no return value, but the resolve/reject signal is useful though :).
`typescript
FolderBsdp.patch("./Users/myname/Documents/Afolder", "./Users/myname/Documents/Bfolder", "./Users/myname/Documents/ABdifference.patch")
``In the code above, both folder A and ABdifference.patch exist beforehand. "./Users/myname/Documents/Bfolder" should not exist beforehand, to which the patching result will be written. In another word, we use the original folder A resource and the difference patch to recover B. If directory "./Users/myname/Documents/Bfolder" exists before the patch method gets executed, it will be deleted when the execution starts. The execution returns a promise. The execution returns a promise, which carries no return value, but the resolve/reject signal is useful though :).