Documentation Index
Fetch the complete documentation index at: https://docs.hyperx.dev/llms.txt
Use this file to discover all available pages before exploring further.
Tag 기반 버전 관리
- 하나의
filename에 대해 optional tag를 붙여 여러 버전을 운영할 수 있습니다.
- 예시:
Items.json (tag 없음)
Items.json (tag = v1)
Items.json (tag = v2)
조회 시 동작:
tag를 지정하면 filename + tag가 정확히 일치하는 객체를 조회합니다.
tag를 생략하면 먼저 tag 없는 객체를 조회합니다.
- tag 없는 객체가 없으면 같은 filename의 버전 중 가장 최근 업데이트 객체를 조회합니다.
파일 정보 조회
await HyperX.Core.PublicStorage.GetMeta("파일명");
- 파일의 개요(메타 정보)를 조회합니다.
GetMeta 함수는 Task<ObjectMeta>를 반환합니다.
- 특정 버전(tag)을 조회하려면
tag named argument를 사용하세요.
await HyperX.Core.PublicStorage.GetMeta("Items.json", tag: "v2");
ObjectMeta는 다음과 같이 이루어진 구조체입니다.
public readonly struct ObjectMeta
{
public readonly string Hash; // 파일의 해시 코드 (파일의 내용이 변경될 때 마다 바뀌는 값)
public readonly string Type; // 파일의 MIME 타입 (예시: "image/png")
public readonly long Size; // byte 단위의 파일 크기
public readonly DateTimeOffset UpdatedAt; // 파일의 최종 업데이트 시각
}
파일 해시 코드 조회
await HyperX.Core.PublicStorage.GetHash("파일명");
- 파일의 해시코드만 필요한 경우에는
GetMeta 함수 대신, GetHash 함수를 이용하여 해시 코드만 빠르게 가져올 수 있습니다.
GetHash 함수는 Task<string>을 반환합니다.
- 특정 버전(tag)을 조회하려면
tag named argument를 사용하세요.
await HyperX.Core.PublicStorage.GetHash("Items.json", tag: "v2");
파일 다운로드
메모리에 파일 내용을 다운로드
HyperX.Core.PublicStorage.Get("파일명");
HyperX.Core.PublicStorage.Get("Items.json", tag: "v2");
스토리지에 파일 내용을 다운로드
HyperX.Core.PublicStorage.Get("파일명", "저장경로");
HyperX.Core.PublicStorage.Get("Items.json", "저장경로", "v2");
상세 설명
- 파일의 실제 내용을 다운로드 받습니다.
Get 함수는 FileDownloadProgress를 반환합니다.
FileDownloadProgress는 다음과 같이 이루어진 클래스입니다.
public class FileDownloadProgress
{
public Task<byte[]> File; // 파일의 내용
public long FileSize; // 파일 전체 크기 (단위: byte)
public long DownloadedSize; // 현재까지 다운로드 된 파일 크기 (단위: byte)
public double Progress; // 파일 다운로드의 진행 정도를 0부터 100까지의 값으로 나타냅니다.
public FileDownloadStatus Status; // 파일 다운로드 작업의 상태를 나타냅니다.
}
public enum FileDownloadStatus
{
PENDING = 0,
IN_PROGRESS = 1,
COMPLETE = 2,
FAILURE = 3
}
Get에 두번째 인자로 파일이 저장될 경로를 지정하면, 다운로드 작업이 완료되어도 File 객체의 값은 null입니다.
- 단, 파일 다운로드가 완료된 경우 Task 자체는 완료됩니다.
- Unity 환경에서 저장경로를 지정 하는 경우,
Application.persistentDataPath 이하 경로에 파일이 다운로드 됩니다.
Unity 코드 예시
다음은 Unity에서 파일의 다운로드 여부를 확인하고, 파일을 다운로드 받아 사용하는 예시를 보여줍니다.
using System.IO;
using UnityEngine;
using UnityEngine.UI;
public class Sandbox : MonoBehaviour
{
public Image imageComponent;
private HyperX.Http.FileDownloadProgress fileDownloadProgress;
async void Start()
{
string fileName = "hyperx.png";
string downloadPath = "/AdditionalAssets/hyperx.png";
string serverHash = await HyperX.Core.PublicStorage.GetHash(fileName);
string localHash = PlayerPrefs.GetString($"DOWNLOADED_FILE_HASH:{fileName}");
if (serverHash == localHash)
{
Debug.Log("이미 최신 파일이 다운로드 되어있습니다.");
}
else
{
Debug.Log("파일 다운로드를 시작합니다.");
fileDownloadProgress = HyperX.Core.PublicStorage.Get("hyperx.png", downloadPath);
await fileDownloadProgress.File;
PlayerPrefs.SetString($"DOWNLOADED_FILE_HASH:{fileName}", serverHash);
Debug.Log("파일 다운로드가 완료되었습니다.");
}
byte[] imageByte = File.ReadAllBytes(Application.persistentDataPath + downloadPath);
Texture2D texture = new Texture2D(200, 200);
texture.LoadImage(imageByte);
Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
imageComponent.sprite = sprite;
}
void Update()
{
if (
fileDownloadProgress != null
&& fileDownloadProgress.Status == HyperX.Http.FileDownloadStatus.IN_PROGRESS
)
{
Debug.Log($"파일 다운로드 진행 상태: {fileDownloadProgress.Progress}%");
}
}
}