From 32fe58b2678dd47d38d611c5fcf64dc62d14e9f0 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Mon, 5 Aug 2024 11:28:17 +0100 Subject: [PATCH] docs(readme): add example for removing dumped images in cwd --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index 252f6b2..b00dc67 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,30 @@ unRTF }); ``` +### Removing images generated by UnRTF + +As mentioned in the note block at the top of this README, the `noPictures` option does not remove images +when used with UnRTF < v0.20.4 and will write them to the current working directory. +To remove images generated by UnRTF it is recommended to use a globbing module such as [glob](https://www.npmjs.com/package/glob) in conjunction with the `node:fs/promises` module to find and remove them: + +```js +import { unlink } from "node:fs/promises"; +import { UnRTF } from "node-unrtf"; +import { glob } from "glob"; + +const file = "test_resources/test_files/test-rtf-complex.rtf"; +const unRtf = new UnRTF(); +const options = { + outputHtml: true, + noPictures: true, +}; + +await unRtf.convert(file, options); + +const files = await glob("*.{emf,wmf}"); +await Promise.all(files.map((filed) => unlink(filed))); +``` + ## Contributing Contributions are welcome, and any help is greatly appreciated!