github.com/wbrown/gpt_bpe@v0.0.0-20250709161131-1571a6e8ad2d/resources/resources_web.go (about)

     1  //go:build js || wasip1
     2  
     3  package resources
     4  
     5  import (
     6  	"bytes"
     7  	"errors"
     8  	"io"
     9  	"strings"
    10  )
    11  
    12  // GetEmbeddedResource
    13  // Returns a ResourceEntry for the given resource name that is embedded in
    14  // the binary.
    15  func GetEmbeddedResource(path string) *ResourceEntry {
    16  	resourceBytes, err := ReadFile(path)
    17  	if err != nil {
    18  		return nil
    19  	}
    20  	resourceWrapper := bytes.NewReader(resourceBytes)
    21  	return &ResourceEntry{resourceWrapper, &resourceBytes}
    22  }
    23  
    24  // EmbeddedDirExists
    25  // Returns true if the given directory is embedded in the binary, otherwise
    26  // false and an error.
    27  func EmbeddedDirExists(path string) (bool, error) {
    28  	ks := MapKeys()
    29  	for _, k := range ks {
    30  		if strings.HasPrefix(k, path+"/") {
    31  			return true, nil
    32  		}
    33  	}
    34  	return false, errors.New("Directory not found")
    35  }
    36  
    37  // FetchHTTP
    38  // Stub for fetching a resource from a remote HTTP server.
    39  func FetchHTTP(uri string, rsrc string, auth string) (io.ReadCloser, error) {
    40  	return nil, errors.New("FetchHTTP not implemented")
    41  }
    42  
    43  // SizeHTTP
    44  // Stub for getting the size of a resource from a remote HTTP server.
    45  func SizeHTTP(uri string, rsrc string, auth string) (uint, error) {
    46  	return 0, errors.New("SizeHTTP not implemented")
    47  }