GW2GetFileTypeID
모든 파일 형식에는 Glasswall Engine에서 연결된 ID가 있습니다. 이 API는 제공된 관련 파일 확장자에 대한 Glasswall 파일 형식 ID를 문자열 형식으로 제공합니다.
- C++
- C#
- Java
- Python
- JavaScript
#include "glasswall.core2.api.h"
int GW2GetFileTypeID(
Session session,
const char *fileType,
size_t *bufferLength,
char **outputBuffer);
매개변수
session GW2OpenSession에서 반환된 세션의 ID
fileType 파일 확장자를 포함하는 문자열입니다. 예: "bmp".
bufferLength outputBuffer가 가리키는 메모리의 바이트 단위 크기로 채워지는 출력 매개변수입니다.
outputBuffer 제공된 확장자와 연결된 파일 type ID로 채워지는 문자열 포인터 출력 매개변수입니다. 이 포인터에 사용된 메모리는 사용자가 해제할 필요가 없습니다.
반환값
함수 호출이 성공했는지를 나타내는 정수를 반환합니다. 음수는 실패를 나타냅니다. 반환 코드에 대한 설명은 Return Types 표를 참조하세요. 성공하면 outputBuffer가 파일 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)
반환값
정수 GW2_RetStatus enum 값을 반환합니다. 음수는 실패를 나타냅니다. 성공하면 출력 버퍼가 파일 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)
반환값
정수 GW2_RetStatus enum 값을 반환합니다. 음수는 실패를 나타냅니다. 성공하면 출력 버퍼가 파일 형식 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);
...