ZIP and BASE64 Handling

Native C API

Helper functions for explicitly decoding BASE64 input and extracting ZIP archives.

Selected SDK inputs also support automatic decoding and extraction; see Passing Files for supported inputs and limitations.

Automatic loading may use temporary files. To reuse extracted files across SDK calls, use the TecUnzipper functions and pass the resulting filenames to the SDK. Release the helper resources when no longer needed, as shown below.

  • Some declarations

    ERRCODE eCode       = ErrOk;
    LPCSTR  pszFilename = "repository.zip";
  • Allocate an unzipper handle

    HTUNZIPPER hZip = TecUnzipper_Alloc( pszFilename );
    if( !hZip )
      return ERROR_OUTOFMEMORY;
  • Make sure that data is always BASE64 decoded. Not required in this case, but should be always done so that you can pass strings starting with "BASE64:" to TecUnzipper_Alloc

    TecUnzipper_Base64Decode( hZip );
  • Extract data to a temporary directory

    eCode = TecUnzipper_Extract( hZip, NULL );
  • Check the return code to see if extracting was successful

    if( eCode == ErrOk )
    {
  • Find the first Repository in the zip file

    INT nIndex  = TecUnzipper_FindFileByExt( hZip, "TFR", -1, TRUE );
    if( nIndex == -1 )
  • The zip archive does not contain a TFORMer Repository file.

      eCode = ERROR_FILE_NOT_FOUND;
    else
  • Get the absolute path to the extracted Repository file.

        pszFilename = TecUnzipper_GetFile( hZip, nIndex );
    }
    else
    {
  • The passed filename was neither a zip file nor a base 64 encoded string. Ignore the error and work with the data as a normal TFR file.

      pszFilename = TecUnzipper_GetFilename( hZip );
      eCode       = ErrOk;
    }
  • pszFilename contains now the path to a normal temporary TFR file

  • Do something with pszFilename now ...

  • Delete created temporary files

    TecUnzipper_DeleteAllFiles( hZip );
  • Free the unzipper handle

    TecUnzipper_Free( hZip );
NameKindPurpose
TecUnzipper_Allocfunction Allocate a new unzipper handle.
TecUnzipper_Freefunction Frees an unzipper-handle allocated by TecUnzipper_Alloc.
TecUnzipper_DeleteAllFilesfunction Deletes all files and directories on disk that have been created by TecUnzipper_Extract.
TecUnzipper_Base64Decodefunction Tests if the passed to TecUnzipper_Alloc is a BASE64 encoded string and decodes it to a temporary file.
TecUnzipper_Extractfunction Extracts a ZIP file into a temporary directory.
TecUnzipper_GetFileCountfunction Returns the number of files that have been extracted.
TecUnzipper_GetFilefunction Returns the filename with the specified index (0..TecUnzipper_GetFileCount - 1).
TecUnzipper_FindFileByExtfunction Finds the first file in the set of extracted files that matches the specified file extension.
TecUnzipper_Base64_Encodefunction Creates a BASE64 encoded string.
TecUnzipper_Base64_Freefunction Free a BASE64 encoded string created with TecUnzipper_Base64_Encode.
TecUnzipper_GetFilenamefunction Returns the filename of the zip file being used or of the temp file created by TecUnzipper_Base64Decode.

Search documentation

Search in
More scopes
Additional scopes

All contents