Function Repository Resource:

CompressCloudObject

Source Notebook

Compress the contents of a cloud object that contains a Wolfram Language expression

Contributed by: Richard Hennigan (Wolfram Research)

ResourceFunction["CompressCloudObject"][obj]

compresses the contents of the CloudObject obj.

ResourceFunction["CompressCloudObject"][obj,target]

compresses a copy of obj at target.

Details and Options

The types of cloud objects supported are generally those that are created with CloudPut.
In ResourceFunction["CompressCloudObject"][obj], the cloud object obj will be overwritten.
Cloud objects compressed by ResourceFunction["CompressCloudObject"] are self-extracting, and will still work with CloudGet.

Examples

Basic Examples (2) 

Compress the contents of a CloudObject:

In[1]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/a8627186-3f14-4452-b6b2-d37a803648da"]
Out[3]=

In[4]:=
ResourceFunction["CompressCloudObject"][CloudObject["temp"]]
Out[4]=

The size of the CloudObject is reduced:

In[5]:=
FileByteCount[CloudObject["temp"]]
Out[5]=

The content is preserved:

In[6]:=
CloudGet["temp"]
Out[6]=
In[7]:=
% === img
Out[7]=

Scope (3) 

Specify a target location:

In[8]:=
original = CloudPut[RandomInteger[100, 10000]]
Out[8]=
In[9]:=
new = ResourceFunction["CompressCloudObject"][original, CloudObject[]]
Out[9]=

The original file remains unchanged:

In[10]:=
CloudGet[original] === CloudGet[new]
Out[10]=

The new file is much smaller:

In[11]:=
FileByteCount[new]/FileByteCount[original] // N
Out[11]=

Generalizations and Extensions (1) 

The content of the compressed CloudObject is an unevaluated Uncompress expression:

In[12]:=
obj = CloudPut[ConstantArray[0, 1000]];
ResourceFunction["CompressCloudObject"][obj]
Out[13]=
In[14]:=
ToExpression[CloudImport[obj, "Text"], InputForm, Hold]
Out[14]=
In[15]:=
ReleaseHold[%] // Short
Out[15]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.0 – 10 October 2018

License Information