String to ZIP

Hi Brendan,

If this is useful feel free to use it.
It is now in the public domain.


Function Zip(extends s as string, CompressStr as boolean = true) As string
  // ZIP compress or uncompress a string
  // using the einhugur e-CryptIt Engine REALbasic Plugin


  if (s = "") then
    return ""
  end if

  // kIncludeZipLibraries as boolean
  // is an application specific boolean global variable
  // that allows the plugin to be loaded or not loaded
  // on a project by project basis

  #if kIncludeZipLibraries then
    Dim result as string
    Dim z as new ZCompression

    if CompressStr then
      result = z.CompressBytes(s)
    else
result = z.DecompressBytes(s, 10*Len(s)) //just guess 10 times size of the input string
    end

    #if DebugBuild then
      if (z.ErrorValue <> 0) then
        Break // stop here when debugging
        Return "" //hmmm, what to do, what to do...
        // consider throwing a RuntimeException here
// the default case requires the calling method to check for a blank string
      end
    #endif

    if CompressStr then
      Return result //return the zipped string
    else
Return DefineEncoding(result, Encodings.UTF8) //return the UTF8 unzipped string
    end

  #else
    Return s //no compression/decompression
  #endif
End Function

--

Cheers,

Dr Gerard Hammond
MacSOS Solutions Pty Ltd
macsos@xxxxxxxxxxxxx  http://www.macsos.com.au

Proofread carefully to see if you any words out.

FTC Website: www.truenorthsoftware.com/Realbasic/FormattedText.html
Set List Options (digest and vacation modes): www.freelists.org/list/ftcdev
List Archive: www.freelists.org/archives/ftcdev
Unsubscribe: Send email to ftcdev-request@xxxxxxxxxxxxx with "unsubscribe" in 
the subject field.


Other related posts: