Skip to content

@vltpkg/registry-client/cache-entry

Classes

CacheEntry

Defined in: cache-entry.ts:57

Constructors

new CacheEntry()
new CacheEntry(
statusCode,
headers,
integrity?): CacheEntry

Defined in: cache-entry.ts:66

Parameters
statusCode

number

headers

Buffer[]

integrity?

`sha512-${string}`

Returns

CacheEntry

Accessors

body
Get Signature
get body(): Buffer | Record<string, any>

Defined in: cache-entry.ts:193

Returns

Buffer | Record<string, any>

headers
Get Signature
get headers(): Buffer[]

Defined in: cache-entry.ts:137

Returns

Buffer[]

integrity
Get Signature
get integrity(): undefined | `sha512-${string}`

Defined in: cache-entry.ts:161

Returns

undefined | `sha512-${string}`

integrityActual
Get Signature
get integrityActual(): `sha512-${string}`

Defined in: cache-entry.ts:154

Returns

`sha512-${string}`

isGzip
Get Signature
get isGzip(): boolean

Defined in: cache-entry.ts:213

Returns

boolean

isJSON
Get Signature
get isJSON(): boolean

Defined in: cache-entry.ts:198

Returns

boolean

statusCode
Get Signature
get statusCode(): number

Defined in: cache-entry.ts:134

Returns

number

valid
Get Signature
get valid(): boolean

Defined in: cache-entry.ts:105

true if the entry represents a cached response that is still valid to use.

Returns

boolean

Methods

[kCustomInspect]()
kCustomInspect: string

Defined in: cache-entry.ts:86

Parameters
depth

number

options

InspectOptions

Returns

string

addBody()
addBody(b): void

Defined in: cache-entry.ts:129

Parameters
b

Buffer

Returns

void

buffer()
buffer(): Buffer

Defined in: cache-entry.ts:182

Return the body of the entry as a Buffer

Returns

Buffer

checkIntegrity()
checkIntegrity(): boolean

Defined in: cache-entry.ts:150

check that the sri integrity string that was provided to the ctor matches the body that we actually received. This should only be called AFTER the entire body has been completely downloaded.

Note that this will usually not be true if the value is coming out of the cache, because the cache entries are un-gzipped in place. It should only be called for artifacts that come from an actual http response.

Returns

boolean

encode()
encode(): Buffer

Defined in: cache-entry.ts:315

Encode the entry as a single Buffer for writing to the cache

Returns

Buffer

getHeader()
getHeader(h): undefined | Buffer

Defined in: cache-entry.ts:168

Give it a key, and it’ll return the buffer of that header value

Parameters
h

string

Returns

undefined | Buffer

json()
json(): JSONObj

Defined in: cache-entry.ts:265

Parse the entry body as JSON and return the result

Returns

JSONObj

setHeader()
setHeader(h, value): void

Defined in: cache-entry.ts:175

Set a header to a specific value

Parameters
h

string

value

string | Buffer

Returns

void

text()
text(): string

Defined in: cache-entry.ts:257

Return the body of the entry as utf8 text Automatically unzips if the content is gzip encoded

Returns

string

unzip()
unzip(): boolean

Defined in: cache-entry.ts:234

Un-gzip encode the body. Returns true if it was previously gzip (so something was done), otherwise returns false.

Returns

boolean

decode()
static decode(buffer): CacheEntry

Defined in: cache-entry.ts:277

Pass the contents of a @vltpkg/cache.Cache object as a buffer, and this static method will decode it into a CacheEntry representing the cached response.

Parameters
buffer

Buffer

Returns

CacheEntry

Type Aliases

JSONObj

type JSONObj = Record<string, JSONField>

Defined in: cache-entry.ts:30