Wolfram Computation Meets Knowledge

CompressCloudObject

Contributed by: Richard Hennigan (Wolfram Research)

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

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

Compress the contents of a CloudObject:

In[1]:=
CloudGet["https://www.wolframcloud.com/objects/aec77503-7166-4383-b025-3d92a4f8827f"] (* Evaluate this cell to copy the example input from a cloud object *)
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]=

More Examples

Scope

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 & Extensions

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]=

Resource History