GW2GetFileType
Ang mga file type ID ay itinatapat sa mga uri ng file na sinusuportahan ng Glasswall Engine. Ibinibigay ng API na ito ang pormal na pangalan ng uri ng file sa string format batay sa isang file type ID number.
- C++
- C#
- Java
- Python
- JavaScript
#include "glasswall.core2.api.h"
int GW2GetFileType(
Session session,
size_t fileId,
size_t *bufferLength,
char **outputBuffer);
Mga Parameter
session Ang ID ng session gaya ng ibinalik ng GW2OpenSession
fileId Isang integer na kumakatawan sa file type ID
bufferLength Isang output parameter na pinupunan ng laki sa bytes ng memory na tinutukoy ng outputBuffer.
outputBuffer Isang string pointer output parameter na pinupunan ng pormal na pangalan ng file type na nauugnay sa ibinigay na file ID, hal. "BMP Image". Ang memory na ginagamit ng pointer na ito ay hindi kailangang i-free ng user.
Ibinabalik
Nagbabalik ng integer na nagsasaad kung matagumpay ang function call. Ang mga negatibong numero ay nagpapahiwatig ng pagkabigo. Tingnan ang talahanayang Return Types para sa paliwanag ng mga return code. Kapag matagumpay, ang outputBuffer ay pinupunan ng pormal na pangalang nauugnay sa file type.
Halimbawa
#include "glasswall.core2.api.h"
#include "filetype.h" // ft_t enum which includes ft_bmp
char *outbuf = NULL;
size_t buflen = 0;
if (GW2OpenSession() < 0)
/* Error opening session */
else
{
int status = GW2GetFileType(session, ft_bmp, &buflen, &outbuf);
/* In this example outbuf will point to the string "BMP Image". */
if (GW2CloseSession() < 0)
/* Error closing session */
}
Buod
public int GW2GetFileType(
int session,
uint fileID,
ref UIntPtr bufferLength,
out IntPtr outputBuffer)
Ibinabalik
Nagbabalik ng integer na GW2_RetStatus enum value. Ang mga negatibong numero ay nagpapahiwatig ng pagkabigo. Kapag matagumpay, ang output buffer ay
pinupunan ng pormal na pangalan ng file type.
Halimbawa
using glasswall_core2;
...
Glasswall glasswall = new Glasswall(); // Instance of the Glasswall wrapper
int session = glasswall.OpenSession();
int returnStatus = glasswall.GW2GetFileType(session, 22, ref bufferLength, out buffer);
if (bufferLength >= 0)
{
byte[] msgArray = glasswall.CreateArrayFromBuffer(buffer, bufferLength);
// Formal name for file type ID 22 now stored in a byte array
}
if (glasswall.CloseSession(session))
{
// Error Handling
}
Buod
import com.glasswall.core2javabridge.*;
public String GW2GetFileTypeString(int session, int fileId) throws GlasswallException
Tandaan
Dati, ang functionality na ito ay nangangailangan ng dalawang magkahiwalay na function call para makuha ang file type data. Na-streamline na ito ngayon upang ibalik ang settings bilang isang String. Ang dalawang orihinal na function ay deprecated na.
Ibinabalik
Ang GW2GetFileTypeString function ay nagbabalik ng isang String na representasyon ng isang filetype ID.
Isang GlasswallException exception ang ita-throw kung hindi valid ang session, o kung hindi makuha ang file type.
Buod - Mga Hindi na Inirerekomendang Function
import com.glasswall.core2javabridge.*;
(Deprecated)
public int GW2GetFileType(int session, int fileId) throws GlasswallException
public byte[] GetFileTypeBuffer(int session) throws GlasswallException
Paglalarawan - Mga Deprecated na Function
Ang function na GW2GetFileType ay naglalabas ng representasyon ng fileId para sa session na tinukoy ng session, papunta sa internal FileType Buffer. Kunin ang data na ito sa pamamagitan ng paggamit ng function na GetFileTypeBuffer.
Mga Return - Mga Hindi na Inirerekomendang Function
Ang function na GW2GetFileType ay nagbabalik ng GW2_RetStatus enumeration na na-convert sa int. Magiging negatibo ang value kung may naganap na error. Ang 0 ay nagpapahiwatig ng tagumpay. Tingnan ang API Overview/Return types para sa mga detalye.
Ang function na GetFileTypeBuffer ay nagbabalik ng UTF-8 encoded na byte[] na naglalaman ng representasyon ng isang filetype ID. Magiging null ito kung hindi pa natawag ang GW2GetFileType.
Isang GlasswallException exception ang ita-throw kung hindi valid ang session, o kung hindi makuha ang file type.
Buod
Kunin ang impormasyon tungkol sa isang uri ng file batay sa identifier nito.
def get_file_type_info(self, file_type: Union[str, int]):
""" Retrieve information about a file type based on its identifier.
Args:
file_type (Union[str, int]): The file type identifier. This can be either a string representing a file
extension (e.g. 'bmp') or an integer corresponding to a file type (e.g. 29).
Returns:
- file_type_info (Union[int, str]): Depending on the input 'file_type':
- If `file_type` is a string (e.g. 'bmp'):
- If the file type is recognised, returns an integer corresponding to that file type.
- If the file type is not recognised, returns 0.
- If `file_type` is an integer (e.g. 29):
- If the integer corresponds to a recognised file type, returns a more detailed string description
of the file type (e.g. 'BMP Image').
- If the integer does not match any recognised file type, returns an empty string.
"""
Ibinabalik
Nagbabalik ng integer o string depende sa input na 'file_type'. Ang value na ito ay maaaring integer ng isang kinikilalang uri ng file, isang detalyadong string description ng isang kinikilalang uri ng file, o kung hindi kinilala ang input na 'file_type', 0 o isang walang lamang string.
Buod
Ang function na ito ay naglalagay ng pointer sa isang description ng tinukoy na fileID sa isang tinukoy na lokasyon.
/**
*
* @param {number} session The ID of the session.
* @param {number} fileID The ID of the file type.
* @param {number} bufferLength The length of the buffer.
* @param {string} outputBuffer The location of the output buffer.
*/
GW2GetFileType(
session,
fileID,
bufferLength,
outputBuffer)
Ibinabalik
Nagbabalik ng integer na GW2_RetStatus enum value. Ang mga negatibong numero ay nagpapahiwatig ng pagkabigo. Kung matagumpay, mapupunan ang output buffer ng pormal na pangalan ng uri ng file.
Halimbawa
const ref = require('ref-napi');
...
function buffer_to_string(buffer, buffer_size) {
if (!buffer.isNull() && ref.deref(buffer_size) > 0) {
return Buffer.from(ref.reinterpret(ref.deref(buffer), ref.deref(buffer_size), 0)).toString();
}
else {
return "";
}
}
...
output_file_buffer = ref.alloc(ref.refType(ref.types.CString));
output_buffer_size = ref.alloc(ref.types.size_t, 0);
return_status = gw.GW2GetFileType(session_id, 22, output_buffer_size, output_file_buffer);
let error_description = buffer_to_string(output_file_buffer, output_buffer_size);
...