Archiver Object Members in SuiteScript for File Compression

The Archiver object in SuiteScript allows server scripts to manage file archiving efficiently with customizable methods.

·2 min read·View Oracle Docs

The Archiver object in SuiteScript enables the creation and management of archive files through specific methods. This object is particularly useful for developers looking to package files for easier storage and transfer.

What Is the Archiver Object?

The Archiver object is part of the N/compress module, designed to facilitate the creation of archive files. You can utilize it by invoking the compress.createArchiver() method. This powerful feature allows server scripts to manage file archiving effectively.

Available Methods

The Archiver object includes two primary methods that enable file management:

Archiver.add(options)

  • Return Type/Value Type: void

  • Supported Script Types: Server scripts

  • Description: This method adds a file to the archive. The path for the target file can be specified using options.directory. If not specified, the file is placed in the root directory of the archive.

    suitescript
    1// Add additional code
    2var archiver = compress.createArchiver();
    3archiver.add({
    4 file: myJpegFile,
    5 directory: 'pics/'
    6});
    7archiver.add({
    8 file: myTxtFile
    9});
    10// Add additional code

Archiver.archive(options)

  • Return Type/Value Type: [file.File]
  • Supported Script Types: Server scripts
  • Description: This method creates an archive from the added files and returns a temporary file object representing the archive.

Error Handling

When using the Archiver methods, be aware of the following error codes:

  • COMPRESS_API_DUPLICATE_PATH: Triggered when a file has already been added using the same target path.
  • COMPRESS_API_FILE_IS_TOO_LARGE: Triggered if the file exceeds size limits; maximum for standard files is 680MB, while binary/ASCII files can be up to 2GB.

Key Considerations

  • Ensure you manage paths correctly to avoid the duplicate path error.
  • Monitor file sizes to prevent compression failures.

Who This Affects

  • Developers: Using suite scripts for automating file archiving processes.
  • Administrators: Responsible for overseeing script functionality and managing scripts in the NetSuite environment.

Key Takeaways

  • The Archiver object provides a streamlined way to manage file compression in SuiteScript.
  • Understanding options for file paths can prevent common errors during compression.
  • Monitoring file sizes is crucial for successful archiving processes.

Frequently Asked Questions (4)

How can I specify a directory for a file when adding it to an archive using the Archiver object?
You can specify a directory for a file by using the `options.directory` parameter in the `archiver.add()` method. If not specified, the file will be placed in the root directory of the archive.
What should I do to prevent the COMPRESS_API_DUPLICATE_PATH error?
Ensure that each file is added with a unique target path. Duplicate paths occur when the same target path is used for multiple files during the archiving process.
What file size limits should I be aware of when using the Archiver object for compression?
Standard files can be up to 680MB, while binary or ASCII files have a limit of 2GB. Exceeding these limits will trigger the `COMPRESS_API_FILE_IS_TOO_LARGE` error.
Can the Archiver object be used in client-side scripts?
No, the Archiver object's methods are supported only in server-side scripts within NetSuite.
Source: Archiver Object Members Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in Platform

View all Platform articles →