UnixCompress React Native Reference Documentation
UnixCompress
Current Version: 11.6.1
Chilkat.UnixCompress
Compress files, memory data, or strings into UNIX
Expand UNIX-compressed data back to files, memory, byte arrays, or text
depending on the application workflow.
Compress and uncompress directly between input and output files when
working with existing filesystem data.
Work with compressed or uncompressed byte data in memory when temporary
files are not desired.
Compress and uncompress text using an explicit character set so string
data round-trips correctly.
Use
For an extended overview, see
UnixCompress Class Overview.
Compress, uncompress, and unpack legacy UNIX
.Z files.Chilkat.UnixCompress provides UNIX compress and
uncompress functionality for legacy .Z files. It
supports file-based, memory-based, and string-based workflows, uses LZW
compression, can unpack .tar.Z archives, and includes abort and
progress-related support for longer-running operations.
Compress to .Z
.Z
format using LZW compression.
Uncompress .Z data
File workflows
Memory workflows
String workflows
Unpack tar.Z archives
UnTarZ to decompress and extract legacy
.tar.Z archives in a single workflow.
UnixCompress when the data is in classic UNIX
.Z format or when a .tar.Z archive must be
unpacked. Use Chilkat.Gzip for .gz and
.tar.gz files, Chilkat.Bz2 for
.bz2 files, and Chilkat.Compression for raw
compression algorithms and general-purpose compression workflows.
Object Creation
// npm install @chilkat/react-native react-native-nitro-modules
// (React Native 0.76+ with the New Architecture; then `pod install` for iOS. The Chilkat
// native library is downloaded and verified during the native build -- see the package README.)
import { Chilkat, UnixCompress } from '@chilkat/react-native'
// Once per app start, before any other Chilkat call:
Chilkat.unlockBundle('Anything for 30-day trial') // shorthand for new Global().unlockBundle(..)
const unixCompress = new UnixCompress()
// ... the native object is released when `unixCompress` is garbage collected, or now with unixCompress.dispose()Creates the underlying native Chilkat object. UnixCompress is a Nitro Module HybridObject: use it from the JavaScript thread only (it cannot be passed to a Worklet or another runtime). Every member is synchronous and blocks the JavaScript thread until Chilkat returns; a method that can take a while also exists as a ...Async twin returning a Promise, which runs the same call on a native worker thread so the UI keeps rendering. While such a call is pending, every other call on this object throws, except abort() and assigning onPercentDone / onProgressInfo.
Releases the native object immediately instead of waiting for garbage collection (useful for a large BinData or an open socket). Calling it more than once is harmless; any other use of the object afterwards throws. An object with a pending ...Async call cannot be disposed until the promise settles.
Errors
A method that can fail throws a plain Error: a method whose only outcome is success or failure returns void and throws on failure; a method producing a string or an object returns it and throws where Chilkat would have returned null. The error's message is "Class.method(...): reason", where the reason is the last informative line of the object's lastErrorText, which holds the full Chilkat log of the failed call. A ...Async twin rejects its promise with the same Error instead of throwing. Properties never throw, and methods that answer a question (has..., is..., ...) return a plain boolean.
try {
unixCompress.someMethod(...)
} catch (e) {
console.log((e as Error).message) // UnixCompress.someMethod(...): <reason>
console.log(unixCompress.lastErrorText) // the full Chilkat log of the failed call
}
// The same call without blocking the JavaScript thread:
try {
await unixCompress.someMethodAsync(...)
} catch (e) {
console.log((e as Error).message) // UnixCompress.someMethodAsync: <reason>
}
Properties
AbortCurrent
abortCurrent: boolean
When set to true, causes the currently running method to abort. Methods that always finish quickly (i.e.have no length file operations or network communications) are not affected. If no method is running, then this property is automatically reset to false when the next method is called. When the abort occurs, this property is reset to false. Both synchronous and asynchronous method calls can be aborted. (A synchronous method call could be aborted by setting this property from a separate thread.)
DebugLogFilePath
debugLogFilePath: string
If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.
Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.
Possible causes of hangs include:
- A timeout property set to 0, indicating an infinite timeout.
- A hang occurring within an event callback in the application code.
- An internal bug in the Chilkat code causing the hang.
HeartbeatMs
heartbeatMs: number
The interval in milliseconds between each AbortCheck event callback, which enables an application to abort certain method calls before they complete. By default, HeartbeatMs is set to 0, meaning no AbortCheck event callbacks will trigger.
LastErrorHtml
readonly lastErrorHtml: string
Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastErrorText
readonly lastErrorText: string
Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
LastErrorXml
readonly lastErrorXml: string
Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastMethodSuccess
lastMethodSuccess: boolean
Indicates the success or failure of the most recent method call: true means success, false means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.
VerboseLogging
verboseLogging: boolean
If set to true, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is false. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.
Version
readonly version: string
Methods
CompressFile
Compresses a file to create a UNIX compressed file (.Z). This compression uses the LZW (Lempel-Ziv-Welch) compression algorithm.
Returns normally on success; throws an Error on failure.
CompressFileAsync
Asynchronous form of CompressFile: the same call on a native worker thread, so the JavaScript thread (and the UI) stays responsive. Takes the same arguments and resolves with the same result. While the returned Promise is pending, every other call on this object throws (the object is busy), except abort(), which cancels the call, and assigning the onPercentDone / onProgressInfo callbacks, which report its progress.
Note: the onPercentDone and onProgressInfo callbacks run on the JavaScript thread while the promise is pending, so they can update the UI directly. A rejection's message is "Class.methodAsync: reason"; the full log is in lastErrorText.
Returns a Promise that resolves with the synchronous method's result (undefined for a void method) and rejects with an Error where the synchronous method would throw.
CompressStringToFile
Unix compresses and creates a .Z file from string data. The charset specifies the character encoding used for the byte representation of the characters when compressed. The charset can be any one of a large number of character encodings, such as utf-8, iso-8859-1, Windows-1252, ucs-2, etc.
Returns normally on success; throws an Error on failure.
UncompressFile
Uncompresses a .Z file. (This compression uses the LZW (Lempel-Ziv-Welch) compression algorithm.)
Returns normally on success; throws an Error on failure.
UncompressFileAsync
Asynchronous form of UncompressFile: the same call on a native worker thread, so the JavaScript thread (and the UI) stays responsive. Takes the same arguments and resolves with the same result. While the returned Promise is pending, every other call on this object throws (the object is busy), except abort(), which cancels the call, and assigning the onPercentDone / onProgressInfo callbacks, which report its progress.
Note: the onPercentDone and onProgressInfo callbacks run on the JavaScript thread while the promise is pending, so they can update the UI directly. A rejection's message is "Class.methodAsync: reason"; the full log is in lastErrorText.
Returns a Promise that resolves with the synchronous method's result (undefined for a void method) and rejects with an Error where the synchronous method would throw.
UncompressFileToString
Uncompresses a .Z file that contains a text file. The contents of the text file are returned as a string. The character encoding of the text file is specified by charset. Typical charsets are iso-8859-1, utf-8, windows-1252, shift_JIS, big5, etc.
Throws an Error on failure (where the description says null is returned, the method throws instead).
UncompressFileToStringAsync
Asynchronous form of UncompressFileToString: the same call on a native worker thread, so the JavaScript thread (and the UI) stays responsive. Takes the same arguments and resolves with the same result. While the returned Promise is pending, every other call on this object throws (the object is busy), except abort(), which cancels the call, and assigning the onPercentDone / onProgressInfo callbacks, which report its progress.
Note: the onPercentDone and onProgressInfo callbacks run on the JavaScript thread while the promise is pending, so they can update the UI directly. A rejection's message is "Class.methodAsync: reason"; the full log is in lastErrorText.
Returns a Promise that resolves with the synchronous method's result (undefined for a void method) and rejects with an Error where the synchronous method would throw.
UnTarZ
Unpacks a .tar.Z file. The decompress and untar occur in streaming mode. There are no temporary files and the memory footprint is constant (and small) while untarring.
Returns normally on success; throws an Error on failure.
UnTarZAsync
Asynchronous form of UnTarZ: the same call on a native worker thread, so the JavaScript thread (and the UI) stays responsive. Takes the same arguments and resolves with the same result. While the returned Promise is pending, every other call on this object throws (the object is busy), except abort(), which cancels the call, and assigning the onPercentDone / onProgressInfo callbacks, which report its progress.
Note: the onPercentDone and onProgressInfo callbacks run on the JavaScript thread while the promise is pending, so they can update the UI directly. A rejection's message is "Class.methodAsync: reason"; the full log is in lastErrorText.
Returns a Promise that resolves with the synchronous method's result (undefined for a void method) and rejects with an Error where the synchronous method would throw.
Events
While a method runs, UnixCompress reports progress through two optional callback properties. Assign a function to receive the event, or undefined to stop receiving it. The callbacks are delivered on the JavaScript thread, so they are useful with the ...Async methods: during a synchronous call the JavaScript thread is busy inside Chilkat, and the events can only arrive after it returns.
const unixCompress = new UnixCompress()
unixCompress.onPercentDone = (pct) => setProgress(pct) // pct is 0..100
unixCompress.onProgressInfo = (name, value) => console.log(`${name}: ${value}`)
unixCompress.heartbeatMs = 250 // let abort() take effect within a quarter second
const pending = unixCompress.someMethodAsync(...)
cancelButton.onPress = () => unixCompress.abort() // the promise then rejects
await pendingPercentDone fires when an operation's completion percentage is known; ProgressInfo delivers named progress values (what is reported depends on the class and method). There is no AbortCheck callback: to cancel a pending ...Async call, call abort() on the object. Chilkat notices the request at its next progress check, which happens at least every heartbeatMs milliseconds on the classes that have that property (0, the default, disables the heartbeat, so set it for a responsive cancel), and the promise rejects with Chilkat's abort error. abort() is harmless when nothing is pending.
PercentDone
onPercentDone?: (pctDone: number) => void
This provides the percentage completion for any method involving network communications or time-consuming processing, assuming the progress can be measured as a percentage. This event is triggered only when it's possible and logical to express the operation's progress as a percentage. The pctDone argument will range from 1 to 100. For methods that finish quickly, the number of PercentDone callbacks may vary, but the final callback will have pctDone equal to 100. For longer operations, callbacks will not exceed one per percentage point (e.g., 1, 2, 3, ..., 98, 99, 100).
The PercentDone callback also acts as an AbortCheck event. For fast methods where PercentDone fires, an AbortCheck event may not trigger since the PercentDone callback already provides an opportunity to abort. For longer operations, where time between PercentDone callbacks is extended, AbortCheck callbacks enable more responsive operation termination.
To abort the operation, set the abort output argument to true. This will cause the method to terminate and return a failure status or corresponding failure value.
Example:
unixCompress.onPercentDone = (pct) => {
// pct ranges from 0 to 100.
setProgress(pct) // runs on the JavaScript thread: React state may be updated directly
}
await unixCompress.someMethodAsync(...)
// To stop an operation from within the callback, call unixCompress.abort()ProgressInfo
onProgressInfo?: (name: string, value: string) => void
This event callback provides tag name/value pairs that detail what occurs during a method call. To discover existing tag names, create code to handle the event, emit the pairs, and review them. Most tag names are self-explanatory.
Note: Some Chilkat methods don't fire any ProgressInfo events.
Example:
unixCompress.onProgressInfo = (name, value) => console.log(`${name}: ${value}`)
await unixCompress.someMethodAsync(...)