GW2GetFileTypeID
ทุกประเภทไฟล์มี ID ที่เกี่ยวข้องใน Glasswall Engine API นี้ให้ ID ประเภทไฟล์ของ Glasswall ในรูปแบบสตริงสำหรับนามสกุลไฟล์ที่เกี่ยวข้องที่ระบุมา
- C++
- C#
- Java
- Python
- JavaScript
#include "glasswall.core2.api.h"
int GW2GetFileTypeID(
Session session,
const char *fileType,
size_t *bufferLength,
char **outputBuffer);
พารามิเตอร์
session ID ของ session ตามที่ส่งกลับโดย GW2OpenSession
fileType สตริงที่มีนามสกุลไฟล์ เช่น "bmp".
bufferLength พารามิเตอร์เอาต์พุตซึ่งจะถูกกำหนดค่าเป็นขนาดหน่วยไบต์ของหน่วยความจำที่ outputBuffer ชี้อยู่
outputBuffer พารามิเตอร์เอาต์พุตแบบตัวชี้สตริง ซึ่งจะถูกเติมด้วย file type ID ที่เชื่อมโยงกับนามสกุลที่ระบุ หน่วยความจำที่ใช้โดยตัวชี้นี้ไม่จำเป็นต้องถูก free โดยผู้ใช้
ส่งกลับ
ส่งกลับจำนวนเต็มที่ระบุว่าการเรียกใช้ฟังก์ชันสำเร็จหรือไม่ ตัวเลขติดลบหมายถึงความล้มเหลว ดูตาราง Return Types สำหรับคำอธิบายของรหัสส่งกลับ หากสำเร็จ outputBuffer จะถูกเติมด้วย file type ID.
ตัวอย่าง
#include "glasswall.core2.api.h"
char *outbuf = NULL;
size_t buflen = 0;
if (GW2OpenSession() < 0)
/* error opening session */
else
{
int status = GW2GetFileTypeID(session, fileType, &buflen, &outbuf);
/* outbuf points to a buffer containing the XML file.
* Either process the data pointed to, or copy the data and process it
* after GW2CloseSession is called
*/
if (GW2CloseSession() < 0)
/* error closing session */
}
สรุป
public int GetFileTypeID(
int session,
string fileType,
ref UIntPtr bufferLength,
out IntPtr outputBuffer)
ส่งกลับ
ส่งกลับค่า enum GW2_RetStatus แบบจำนวนเต็ม ตัวเลขติดลบหมายถึงความล้มเหลว หากสำเร็จ output buffer จะถูกเติมด้วย file type ID.
ตัวอย่าง
using glasswall_core2;
...
Glasswall glasswall = new Glasswall(); // Instance of the Glasswall wrapper
int session = glasswall.OpenSession();
int returnStatus = glasswall.GetFileTypeID(session, "pdf", ref bufferLength, out buffer);
if (bufferLength >= 0)
{
byte[] msgArray = glasswall.CreateArrayFromBuffer(buffer, bufferLength);
// File type ID for PDF is now stored in a byte array
}
if (glasswall.CloseSession(session))
{
// Error Handling
}
สรุป
ไม่รองรับใน Java
สรุป
ดึงข้อมูลเกี่ยวกับประเภทไฟล์ตามตัวระบุของประเภทนั้น
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.
"""
ส่งกลับ
ส่งคืนจำนวนเต็มหรือสตริงตามค่าอินพุต 'file_type' ค่านี้อาจเป็นจำนวนเต็มของประเภทไฟล์ที่รู้จัก คำอธิบายแบบสตริงโดยละเอียดของประเภทไฟล์ที่รู้จัก หรือหากไม่รู้จักค่าอินพุต 'file_type' จะเป็น 0 หรือสตริงว่าง
สรุป
ฟังก์ชันนี้จะวางตัวชี้ไปยังคำอธิบายของ fileType ที่ระบุไว้ในตำแหน่งที่กำหนด
/**
*
* @param {number} session The ID of the session.
* @param {string} fileType The extension of the file type.
* @param {number} bufferLength The length of the buffer.
* @param {string} outputBuffer The location of the output buffer.
*/
GW2GetFileTypeID(
session,
fileType,
bufferLength,
outputBuffer)
ส่งกลับ
ส่งกลับค่า enum GW2_RetStatus แบบจำนวนเต็ม ตัวเลขติดลบหมายถึงความล้มเหลว หากสำเร็จ output buffer จะถูกเติมด้วย file type ID.
ตัวอย่าง
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.GW2GetFileTypeID(session_id, "pdf", output_buffer_size, output_file_buffer);
let error_description = buffer_to_string(output_file_buffer, output_buffer_size);
...