GW2GetFileTypeID
Mỗi loại tệp có một ID liên kết trong Glasswall Engine. API này cung cấp ID loại tệp Glasswall ở định dạng chuỗi cho phần mở rộng tệp liên quan được cung cấp.
- C++
- C#
- Java
- Python
- JavaScript
#include "glasswall.core2.api.h"
int GW2GetFileTypeID(
Session session,
const char *fileType,
size_t *bufferLength,
char **outputBuffer);
Tham số
session ID của phiên như được trả về bởi GW2OpenSession
fileType Một chuỗi chứa phần mở rộng tệp. Ví dụ: "bmp".
bufferLength Một tham số đầu ra được điền kích thước tính bằng byte của vùng nhớ được trỏ tới bởi outputBuffer.
outputBuffer Một tham số đầu ra con trỏ chuỗi được điền bằng ID loại tệp liên kết với phần mở rộng được cung cấp. Bộ nhớ được sử dụng bởi con trỏ này không cần được người dùng giải phóng.
Giá trị trả về
Trả về một số nguyên cho biết lệnh gọi hàm có thành công hay không. Các số âm cho biết thất bại. Xem bảng Return Types để biết giải thích về các mã trả về. Nếu thành công, outputBuffer sẽ được điền bằng ID loại tệp.
Ví dụ
#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 */
}
Tóm tắt
public int GetFileTypeID(
int session,
string fileType,
ref UIntPtr bufferLength,
out IntPtr outputBuffer)
Giá trị trả về
Trả về một giá trị enum GW2_RetStatus kiểu số nguyên. Các số âm cho biết thất bại. Nếu thành công, bộ đệm đầu ra sẽ được điền bằng ID loại tệp.
Ví dụ
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
}
Tóm tắt
Không được hỗ trợ trong Java
Tóm tắt
Truy xuất thông tin về một loại tệp dựa trên mã định danh của loại đó.
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.
"""
Giá trị trả về
Trả về một số nguyên hoặc chuỗi tùy thuộc vào đầu vào 'file_type'. Giá trị này có thể là số nguyên của một loại tệp được nhận diện, chuỗi mô tả chi tiết của một loại tệp được nhận diện hoặc, nếu đầu vào 'file_type' không được nhận diện, là 0 hoặc chuỗi rỗng.
Tóm tắt
Hàm này đặt một con trỏ tới phần mô tả của fileType được chỉ định vào một vị trí được chỉ định.
/**
*
* @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)
Giá trị trả về
Trả về một giá trị enum số nguyên GW2_RetStatus. Các số âm cho biết có lỗi. Nếu thành công, bộ đệm đầu ra sẽ được điền bằng ID loại tệp.
Ví dụ
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);
...