Create a ZIP File
The following sample creates a ZIP file.
Note:
This sample script uses the require
function so you can copy it into the SuiteScript Debugger and test it. You must use the define
function in an entry point script (a script you attach to a script record and deploy). For more information, see SuiteScript 2.x Script Basics and SuiteScript 2.x Script Types.
require(['N/compress', 'N/file'], function(compress, file) {
// load/create files to be archived
var binaryFile = file.load({
id: 200
});
var textFile = file.create({
name: 'file.txt',
fileType: 'PLAINTEXT',
contents: 'This is sample content.'
});
// create an archive as a temporary file object
var archiver = compress.createArchiver();
archiver.add({
file: binaryFile
});
archiver.add({
file: textFile,
directory: 'txt/'
});
var zipFile = archiver.archive({
name: 'myarchive.zip'
});
// save the archive to file cabinet
zipFile.folder = 123;
zipFile.save();
});