spark.loadText
function loadText(path: string): Promise<string>Load a file from torchjs.org as text (UTF-8).
Convenience function for loading text files. The file is downloaded as an ArrayBuffer and decoded as UTF-8 text.
Use this for:
- README and documentation files
- Configuration files
- Source code or scripts
- Any text-based format
If the file is not valid UTF-8, the decode may produce replacement characters. For binary files, use
load instead.Parameters
pathstring- File path in format "username/project/filename" or "username/project/path/to/file"
Returns
Promise<string>– Promise that resolves to the file contents as a string (UTF-8 decoded)Examples
// Load project documentation
const readme = await spark.loadText('kasumi/mnist/readme.txt');
console.log(readme);
// Load configuration
const config = await spark.loadText('kasumi/project/config.txt');