如何在node.js中提取.rar文件?

Mr *_*old 3 module extract rar node.js

我正在尝试在 Windows 8.1 中使用 node.js 提取 .rar 文件。有什么好的方法可以做到这一点吗?

提前致谢

Mag*_*ull 5

node-unrar-js是一个 JavaScript 中的 Rar 提取器(确切地说是 TS),基于原始源代码。与 Unrar 不同,它不需要在系统上安装外部软件。

我设法使用以下代码在 Linux 上提取 .rar 文件。

import { createExtractorFromFile } from 'node-unrar-js'

async function extractRarArchive(file, destination) {
  try {
    // Create the extractor with the file information (returns a promise)
    const extractor = await createExtractorFromFile({
      filepath: file,
      targetPath: destination
    });

    // Extract the files
    [...extractor.extract().files];
  } catch (err) {
    // May throw UnrarError, see docs
    console.error(err);
  }
}

// Files are put directly into the destination
// The full path of folders are created if they are missing
extractRarArchive("/path/to/archive.rar", "~/Desktop/files");
Run Code Online (Sandbox Code Playgroud)