Don't include parent folder when packing tar

女生的网名这么多〃 提交于 2019-12-14 02:38:44

问题


I created a build system as an npm script, so I'm able to run npm run build -- <DIRECTORY>. This runs the file build.js, which packs a couple of tar archives from the specified directory and moves the resulting tar into the dist directory.

For this I use the package node-tar:

var stream = fstream.Reader({ 
  path: project + "/" + folder
});

stream.pipe(tar.Pack())
  .pipe(fstream.Writer({ path: project + "/" + folder + ".tar" }));

Assume the following directory structure:

folder-a
  test1.xml
  test2.xml
dist
package.json
build.js

When running npm run build -- folder-a, this should create a tar-archive with the contents of folder-a with the following structure:

folder-a.tar
  test1.xml
  test2.xml

What it does though, is the following:

folder-a.tar
  folder-a
    test1.xml
    test2.xml

How can I get rid of the parent directory and put the files directly into the root of the archive?

来源:https://stackoverflow.com/questions/33055288/dont-include-parent-folder-when-packing-tar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!