GW2DetermineFileTypeFromMemory
    • PDF

    GW2DetermineFileTypeFromMemory

    • PDF

    Article summary

    The GW2DetermineFileTypeFromMemory function determines the file type of the file whose content is in the buffer held in memory.

    Synopsis

    #include "glasswall.core2.api.h"
    ft_t GW2DetermineFileTypeFromFile(const char *inputFileBuffer, size_t inputLength);

    Returns

    If GW2DetermineFileTypeFromMemory cannot discern the file type, it returns the value of the enumeration constant ft_unknown from the enumerated type ft_t ; otherwise, it returns a value from the enumerated type ft_t indicating the file type. A list of the enumeration constants is in the C source header file filetypes.h.

    Synopsis

    /// <summary>
    /// Returns a value indicating the the file type from an input file by Glasswall.
    /// </summary>
    /// <param name="inputFileBuffer">The input buffer containing the file to be determined</param>
    /// <returns>A value indicating the determined file type</returns>s
    public int DetermineFileTypeFromMemory(byte[] inputFileBuffer)

    Returns

    A value indicating the determined file type - a list of the enumeration constants is in the C source header file filetypes.h are consistent with the returned value for this function.

    Synopsis

    import com.glasswall.core2javabridge.*;
    
    public int GW2DetermineFileTypeFromMemory(byte[] fileBuffer) throws GlasswallException, NullPointerException
    
    public int GW2DetermineFileTypeFromMemory(byte[] fileBuffer, int length) throws GlasswallException, NullPointerException

    Note:

    The length of the fileBuffer may optionally be specified.

    Returns

    The GW2DetermineFileTypeFromMemory function returns an enumerator of type ft_t converted to an int. A list of the enumeration constants may be found in the C source header file filetypes.h.

    A NullPointerException exception will be thrown if fileBuffer is null or empty.

    A GlasswallException exception will be thrown if fileBuffer cannot be retrieved.

    Synopsis

    Determine the file type of a given input file, either as an integer identifier or a string.

    def determine_file_type(self, input_file: Union[str, bytes, bytearray, io.BytesIO], as_string: bool = False, raise_unsupported: bool = True) -> Union[int, str]:
        """ Determine the file type of a given input file, either as an integer identifier or a string.
    
        Args:
            input_file (Union[str, bytes, bytearray, io.BytesIO]): The input file to analyse. It can be provided as a file path (str), bytes, bytearray, or a BytesIO object.
            as_string (bool, optional): Return file type as string, eg: "bmp" instead of: 29. Defaults to False.
            raise_unsupported (bool, optional): Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
    
        Returns:
            file_type (Union[int, str]): The file type.
        """

    Returns

    A value or extension string indicating the determined file type - A list of the enumeration constants is in the C source header file filetypes.h are consistent with the returned value for this function.

    Synopsis

    /**
     * This function determines the file type for a given file provided it is supported by Glasswall. Notice this is not related to a session.
     * @param {string} path The path to the provided file.
     * @returns {number} The determined file type, as enumerated in the C source header file filetypes.h.
     */
    
    GW2DetermineFileTypeFromMemory(inputFileBuffer, inputLength)
    

    Returns

    A value indicating the determined file type - A list of the enumeration constants is in the C source header file filetypes.h are consistent with the returned value for this function.


    Was this article helpful?