All Projects → pdalcol → Zippex

pdalcol / Zippex

Licence: mit
Native Apex Zip library for Salesforce.com

Labels

Projects that are alternatives of or similar to Zippex

Rflib
Salesforce open source library with logging framework, trigger framework, feature switches, and advanced monitoring capabilities
Stars: ✭ 69 (-34.91%)
Mutual labels:  apex
Apextestkit
A way to simplify your Salesforce data creation.
Stars: ✭ 80 (-24.53%)
Mutual labels:  apex
Sfdx Travisci
Stars: ✭ 95 (-10.38%)
Mutual labels:  apex
Apex Dml Manager
Enforces CRUD/FLS in the least disruptive way possible
Stars: ✭ 70 (-33.96%)
Mutual labels:  apex
Processbuilderblocks
apex invocable methods for use in Process Builder
Stars: ✭ 77 (-27.36%)
Mutual labels:  apex
Dialogue Generation
Generating responses with pretrained XLNet and GPT-2 in PyTorch.
Stars: ✭ 86 (-18.87%)
Mutual labels:  apex
Lwc Recipes
A collection of easy-to-digest code examples for Lightning Web Components on Salesforce Platform
Stars: ✭ 1,147 (+982.08%)
Mutual labels:  apex
Apex Unified Logging
Platform-Event-based Apex logger for unified logging over transaction boundaries
Stars: ✭ 101 (-4.72%)
Mutual labels:  apex
Query.apex
A dynamic SOQL and SOSL query builder on Salesforce.com platform
Stars: ✭ 78 (-26.42%)
Mutual labels:  apex
Awesome Low Code
Awesome Low-Code Application Platforms | 全球低代码平台开发资源大全
Stars: ✭ 90 (-15.09%)
Mutual labels:  apex
Sfdc Convert Attachments To Chatter Files
📎 Easily migrate your Attachments to Salesforce Files.
Stars: ✭ 72 (-32.08%)
Mutual labels:  apex
Visualforce Typeahead
A flexible typeahead component for use on Visualforce pages. Uses the typeahead.js library from Twitter.
Stars: ✭ 73 (-31.13%)
Mutual labels:  apex
Sirono Common
Common Apex utility classes and frameworks used by Sirono products
Stars: ✭ 87 (-17.92%)
Mutual labels:  apex
Cinnamon
Cinnamon is a Force.com app that enables you to build and run Selenium tests to validate custom UI pages with Visualforce/Javascript in your Salesforce org.
Stars: ✭ 70 (-33.96%)
Mutual labels:  apex
Force Dot Com Esapi
Enterprise Security API for the Apex language on the Force.com platform.
Stars: ✭ 98 (-7.55%)
Mutual labels:  apex
Apexunit
ApexUnit is a powerful continuous integration tool for the Force.com platform
Stars: ✭ 69 (-34.91%)
Mutual labels:  apex
Batch Entry For Salesforce.com
jQuery-based quick entry screen that works with any object. Highly configurable and flexible.
Stars: ✭ 82 (-22.64%)
Mutual labels:  apex
Easy Spaces Lwc
Sample application for Lightning Web Components on Salesforce Platform. Part of the sample gallery. Event management use case. Get inspired and learn best practices.
Stars: ✭ 104 (-1.89%)
Mutual labels:  apex
Vim Force.com
Vim plugin for force.com
Stars: ✭ 98 (-7.55%)
Mutual labels:  apex
Automated Testing For Force.com
Salesforce testing automation runs all tests and emails your team. Native Force.com Apex code delivers lightweight Salesforce continuous integration.
Stars: ✭ 88 (-16.98%)
Mutual labels:  apex

Copyright (c) 2015 Pedro Dal Col, Pliny Smith

Zippex (aka Zipper)

Native Apex Zip utility for the salesforce.com platform.

Table of Contents

How to install

Option 1: Manually save files to SF

Copy and paste from this repository the following four classes into new classes in your Salesforce instance.

  1. HexUtil.cls
  2. Puff.cls
  3. Zippex.cls
  4. ZippexTests.cls

Option 2: Use the 'Deploy to Salesforce' button

Deploy to Salesforce

How to use

Constructors:

Zippex()

public Zippex()

Instantiates a new empty Zippex object (empty Zip archive).

Example
Zippex sampleZip = new Zippex();

Zippex(fileData)

public Zippex(Blob fileData)

Instantiates a new Zippex object from an existing Zip file.

Parameters
Name Type Description
fileData Blob Data containing a valid Zip file
Example
Attachment sampleAttachment = [SELECT Name, Body FROM Attachment WHERE Id='<ID_OF_ATTACHMENT>'];
Zippex sampleZip = new Zippex(sampleAttachment.Body);

Public Methods:

addFile(fileName, fileData, crc32)

public void addFile(String fileName, Blob fileData, String crc32)

Adds a new file to the current Zip archive.

Parameters
Name Type Description
fileName String File name including full path
fileData Blob Data containing the file data
crc32 String (optional) little endian hex value of the CRC32. Enter null for addFile to calculate the CRC32 of the fileData
Example
Zippex sampleZip = new Zippex();
Blob fileData = Blob.valueOf('Sample text.');
sampleZip.addFile('sampleFolder/test.txt', fileData, null);
Blob zipData = sampleZip.getZipArchive();

containsFile(fileName)

public Boolean containsFile(String fileName)

Returns true if the current Zip archive contains the specified file.

Parameters
Name Type Description
fileName String File name including full path
Return Boolean Return true if file is in Zip archive
Example
Zippex sampleZip = new Zippex();
sampleZip.addFile('sampleFolder/test.txt', Blob.valueOf('Sample text.'), null);
System.assert(sampleZip.containsFile('sampleFolder/test.txt'));

getFileNames()

public Set<String> getFileNames()

Returns a set of filenames from the current Zip archive.

Parameters
Name Type Description
Return Set<String> Returns all file names including full path in the current Zip archive
Example
Attachment sampleAttachment = [SELECT Name, Body FROM Attachment WHERE Id='<ID_OF_ATTACHMENT>'];
Zippex sampleZip = new Zippex(sampleAttachment.Body);
Set <String> fileNames = sampleZip.getFileNames();
for (String fileName : fileNames)
{
    System.debug('file: ' + fileName);
}

getFile(fileName)

public Blob getFile(String fileName)

Extracts the specified file contents from the current Zip archive. If the file does not exist, returns null.

Parameters
Name Type Description
fileName String File name including full path
Return Blob File data
Example
Zippex sampleZip = new Zippex();
sampleZip.addFile('sampleFolder/test.txt', Blob.valueOf('Sample text.'), null);
Blob fileData = sampleZip.getFile('sampleFolder/test.txt');
System.assertEquals ('Sample text.', fileData.toString());

getFileInfo(fileName)

public Map<String,String> getFileInfo(String fileName)

Returns file metadata (lastModDateTime, crc32, fileSize, fileName, and fileComment).

Parameters
Name Type Description
fileName String File name including full path
Return Map<String,String> Contains values for lastModDateTime, crc32, fileSize, fileName, and fileComment
Example
Zippex sampleZip = new Zippex();
sampleZip.addFile('sampleFolder/test.txt', Blob.valueOf('Sample text.'), null);
Map <String, String> fileInfoMap = sampleZip.getFileInfo('sampleFolder/test.txt');
System.assertEquals ('12', fileInfoMap.get('fileSize'));
System.assertEquals ('sampleFolder/test.txt', fileInfoMap.get('fileName'));

getZipArchive()

public Blob getZipArchive()

Returns a Blob that contains the entire Zip archive.

Parameters
Name Type Description
Return Blob Full Zip archive data
Example
Zippex sampleZip = new Zippex();
sampleZip.addFile('sampleFolder/test.txt', Blob.valueOf('Sample text.'), null);
Blob zipData = sampleZip.getZipArchive();

removeFile(fileName)

public void removeFile(String fileName)

Removes a file from the current Zip archive.

Parameters
Name Type Description
fileName String File name to remove from Zip archive including full path
Example
Zippex sampleZip = new Zippex();
sampleZip.addFile('sampleFolder/file1.txt', Blob.valueOf('Sample text1.'), null);
sampleZip.addFile('sampleFolder/file2.txt', Blob.valueOf('Sample text2.'), null);
System.assert(sampleZip.getFileNames().contains('sampleFolder/file1.txt'));
System.assert(sampleZip.getFileNames().contains('sampleFolder/file2.txt'));
sampleZip.removeFile('sampleFolder/file1.txt');
System.assert(sampleZip.getFileNames().contains('sampleFolder/file1.txt') == false);
System.assert(sampleZip.getFileNames().contains('sampleFolder/file2.txt'));

renameFile(oldName, newName)

public void renameFile(String oldName, String newName)

Renames a file in the current Zip archive.

Parameters
Name Type Description
oldName String The current file name to be modified
newName String The new name that replaces the current file name
Example
Zippex sampleZip = new Zippex();
sampleZip.addFile('sampleFolder/file.txt', Blob.valueOf('Sample text1.'), null);
System.assert(sampleZip.getFileNames().contains('sampleFolder/file.txt'));
sampleZip.renameFile('sampleFolder/file.txt', 'sampleFolder/changedName.txt');
System.assert(sampleZip.getFileNames().contains('sampleFolder/file.txt') == false);
System.assert(sampleZip.getFileNames().contains('sampleFolder/changedName.txt'));

removePrefix(prefix)

public void removePrefix(String prefix)

Removes the specified prefix from all file names in the current Zip archive only if it occurs at the beginning of the file name.

Parameters
Name Type Description
prefix String The prefix to remove from file names
Example
Zippex sampleZip = new Zippex();
sampleZip.addFile('sampleFolder/file.txt', Blob.valueOf('Sample text1.'), null);
System.assert(sampleZip.getFileNames().contains('sampleFolder/file.txt'));
sampleZip.removePrefix('sample');
System.assert(sampleZip.getFileNames().contains('sampleFolder/file.txt') == false);
System.assert(sampleZip.getFileNames().contains('Folder/file.txt'));

unzipAttachment(srcAttId, destObjId, fileNames, attemptAsync)

public static void unzipAttachment(Id srcAttId, Id destObjId, String[] fileNames, Boolean attemptAsync){

Parameters
Name Type Description
srcAttId Id ID of the attachment to unzip
destObjId Id ID of the object to which unzipped files should be attached. If null the ParentId of the Zip archive will be used
fileNames String[] List containing file names to uncompress. If null, all files will be uncompressed
attemptAsync Boolean If true, it attempts to unzip files in a future call
Example
Zippex.unzipAttachment('<ID_OF_ATTACHMENT>', null, null, false);
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].