How to use the create function from tar

Find comprehensive JavaScript tar.create code examples handpicked from public code repositorys.

tar.create is a function provided by the Node.js tar module that creates a new tar archive from a specified directory or file.

130
131
132
133
134
135
136
137
138
139
140


BuildHelper.CompressBuild = function(BuildId, OutputFolder) {
    const BuildFolder = this.GetBuildFolder(BuildId)
    const OutputFile = Path.join(OutputFolder, FS.readJSONSync(`${BuildFolder}/package.info.json`).Id) + ".twr"
    TypeWriter.Logger.Debug(`Outputting to ${OutputFile} in ${BuildFolder}`)
    Tar.create(
        {
            file: OutputFile,
            cwd: BuildFolder,
            sync: true,
fork icon0
star icon2
watch icon0

13
14
15
16
17
18
19
20
21
22
23
24
const APPLICATION_TYPES = ['service', 'db']
const CONFIG_FILE_EXTENSIONS = ['yml', 'yaml', 'json', 'json5', 'tml', 'toml']


async function archiveProject (pathToProject, archivePath) {
  const options = { gzip: false, file: archivePath, cwd: pathToProject }
  return tar.create(options, ['.'])
}


class DeployClient {
  constructor (deployServiceHost, workspaceId, workspaceKey) {
fork icon0
star icon0
watch icon4

+ 13 other calls in file

How does tar.create work?

tar.create is a function provided by the Node.js tar module that creates a new tar archive from a specified directory or file. When you call tar.create, you provide a stream object to write the output to and a configuration object that specifies the options for creating the archive. The configuration object can include various options such as the name of the archive file, the compression format to use, and whether to include or exclude certain files or directories. When creating the archive, tar.create walks through the specified directory recursively, adding each file and subdirectory to the archive. By default, symbolic links are preserved as links, rather than being followed and added to the archive. The resulting tar archive can be written to a file, piped to another stream, or sent over a network connection, depending on your needs. Overall, tar.create provides a convenient and flexible way to create tar archives from files and directories, allowing you to easily package and transport collections of files and directories in a single compressed archive file.

39
40
41
42
43
44
45
46
47
48
  await replication(remote, local)
}
bar.stop()
console.log("S3 Export")
await exportObjects()
tar.create(
  {
    sync: true,
    gzip: true,
    file: filename,
fork icon0
star icon0
watch icon1

152
153
154
155
156
157
158
159
160
161

return BB.resolve(packlist({ path: dir }))
// NOTE: node-tar does some Magic Stuff depending on prefixes for files
//       specifically with @ signs, so we just neutralize that one
//       and any such future "features" by prepending `./`
  .then((files) => tar.create(tarOpt, files.map((f) => `./${f}`)))
  .then(() => getContents(pkg, tmpTarget, filename, logIt))
  // thread the content info through
  .tap(() => {
    if (dryRun) {
fork icon0
star icon0
watch icon0

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
const fs = require("fs");
const tar = require("tar");

// Create a new tar archive from a directory
const archiveName = "example.tar";
const directoryPath = "./example";
const output = fs.createWriteStream(archiveName);
const options = {
  gzip: true,
  filter: (path) => !path.endsWith(".log"),
};

tar.create(options, [directoryPath]).pipe(output);

In this example, tar.create is used to create a new tar archive from the example directory. The resulting archive is named example.tar and compressed using the gzip format. The options object passed to tar.create specifies that files with a .log extension should be excluded from the archive using the filter option. The resulting tar archive is written to a new file using fs.createWriteStream and piped to the output stream. Note that tar.create can be customized with various options to meet the specific needs of your application, allowing you to create tar archives with custom compression, file filtering, and other features.