vanilladocs
vanillapunch.com
API / resource/textasset

resource/textasset

텍스트 애셋.

Text asset.

TextAssetextends Asset

짝Counterpart: vanilla-engine TextAsset

텍스트 애셋.

Text asset.

예제Example캐시 없이 글 파일 받기Fetch a text file without the cache
import { TextAsset } from "./build/vanilla.js";

const textAsset = new TextAsset();
textAsset.setNoCache(true);
await textAsset.load("examples/timelineshowcase/assets/combo.timeline.json");
console.log(textAsset.text.length, textAsset.isNoCache());
생성자constructorconstructor()#0.0.8 부터since 0.0.8소스source

생성.

Constructor.

짝Counterpart: vanilla-engine TextAsset.new

필드fieldtext#0.0.8 부터since 0.0.8소스source

읽은 글. (읽기 전이나 언로드 뒤에는 빈 글)

Loaded text. (empty string before loading or after unloading)

반환Returnsstring

짝Counterpart: vanilla-engine TextAsset.get_text

메서드methodsetNoCache(isNoCache)#0.3.0 부터since 0.3.0소스source

캐시 무효화 로드 여부 설정.

  • 참이면 fetch 에 cache: "no-cache" 를 붙여, 배포 뒤 브라우저가 옛 데이터를 계속 쓰는 문제를 막는다. (데이터 테이블 JSON 등)

Sets whether to load with cache invalidation.

  • If true, adds cache: "no-cache" to fetch, preventing the browser from continuing to use old data after deployment. (data table JSON, etc)
isNoCacheboolean
참이면 캐시를 쓰지 않고 받는다.If true, fetches without using the cache.

짝Counterpart: vanilla-engine TextAsset.set_no_cache

메서드methodisNoCache()#0.3.0 부터since 0.3.0소스source

캐시 무효화 로드 여부 반환.

Returns whether to load with cache invalidation.

반환Returnsboolean 캐시를 쓰지 않고 받으면 참. (기본 거짓)True if fetching without the cache. (default false)

짝Counterpart: vanilla-engine TextAsset.is_no_cache

메서드methodasync load(assetPath)#0.0.8 부터since 0.0.8소스source

비동기 애셋 로드.

Loads the asset asynchronously.

assetPathstring
글 파일 경로. (이미 읽혔으면 아무것도 하지 않는다)Text file path. (does nothing if already loaded)

반환ReturnsPromise<void> 다 읽으면 풀리는 프로미스. (실패 응답이나 받기 실패면 console.error 로 알리고 거부된다)A promise resolved when fully loaded. (on a failed response or fetch failure it reports with console.error and rejects)

짝Counterpart: vanilla-engine TextAsset.load

메서드methodloadFromBytes(assetPath, bytes)#0.4.0 부터since 0.4.0소스source

이미 가진 바이트로 읽기. (UTF-8 로 읽고, UTF-8 이 아닌 바이트는 대체 문자로 바꾼다, 이미 읽혔어도 새 바이트로 바꾼다)

Loads from bytes already held. (Reads as UTF-8, replaces non UTF-8 bytes with the replacement character, replaces with the new bytes even if already loaded)

assetPathstring
getAssetPath 에 쓸 이름.Name used for getAssetPath.
bytesArrayBuffer | ArrayBufferView
글 파일의 바이트. (UTF-8)Bytes of the text file. (UTF-8)

짝Counterpart: vanilla-engine TextAsset.load_from_bytes

메서드methodunload()#0.0.8 부터since 0.0.8소스source

애셋 언로드.

Unloads the asset.

짝Counterpart: vanilla-engine TextAsset.unload