Skip to main content
// Get file from default branch
const resp = await repo.getFileStream({ path: "README.md" });
const text = await resp.text();
console.log(text);

// Get file from specific branch, tag, or commit
const historicalResp = await repo.getFileStream({
  path: "package.json",
  ref: "v1.0.0", // branch name, tag, or commit SHA
});
const historicalText = await historicalResp.text();

// Fetch from the ephemeral namespace
const ephemeralResp = await repo.getFileStream({
  path: "notes.md",
  ref: "feature/demo-work",
  ephemeral: true,
});

const rangedResp = await repo.getFileStream({
  path: "README.md",
  headers: { range: "bytes=0-1023" },
});
console.log(rangedResp.status, rangedResp.headers.get("content-range"));

Options

path
string
required
Path to the file within the repository
ref
string
Branch name, tag, or commit SHA. Defaults to the default branch.
ephemeral
boolean
When true, resolves the ref under the ephemeral namespace.
ephemeralBase
boolean
When true, resolves the base branch under the ephemeral namespace. TypeScript: ephemeralBase; Python: ephemeral_base; Go: EphemeralBase.
headers.range
string
HTTP Range header, such as bytes=0-1023. TypeScript/Python: range; Go: Range.
headers.ifMatch
string
HTTP If-Match header. TypeScript: ifMatch; Python: if_match; Go: IfMatch.
headers.ifNoneMatch
string
HTTP If-None-Match header. TypeScript: ifNoneMatch; Python: if_none_match; Go: IfNoneMatch.
headers.ifModifiedSince
string
HTTP If-Modified-Since header. TypeScript: ifModifiedSince; Python: if_modified_since; Go: IfModifiedSince.
headers.ifUnmodifiedSince
string
HTTP If-Unmodified-Since header. TypeScript: ifUnmodifiedSince; Python: if_unmodified_since; Go: IfUnmodifiedSince.
headers.ifRange
string
HTTP If-Range header. TypeScript: ifRange; Python: if_range; Go: IfRange.
ttl
number
Token TTL in seconds.

Returns

Returns a standard Fetch Response object (TypeScript), an async response object (Python), or an *http.Response (Go) that can be used to stream or read the file content. When range or conditional headers are provided, statuses 206, 304, 412, and 416 are returned to the caller with their response headers.