Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (stripe.file === target.output) {
return cb(wasReported(
'Trying to take executable into executable', stripe.file
));
}
assert.equal(stripe.store, STORE_CONTENT); // others must be buffers from walker
return cb(undefined, pipeToNewMeter(fs.createReadStream(stripe.file)));
} else {
assert(false, 'producer: bad stripe');
}
} else {
payloadSize = track;
preludePosition = payloadPosition + payloadSize;
return cb(undefined, next(
intoStream(makePreludeBufferFromPrelude(
replaceDollarWise(
replaceDollarWise(prelude, '%VIRTUAL_FILESYSTEM%', JSON.stringify(vfs)),
'%DEFAULT_ENTRYPOINT%', JSON.stringify(entrypoint))
))
));
}
} else {
return cb();
}
}).on('error', (error) => {
reject(error);
try {
entry = await pda.stat(archiveFS, path)
entry.path = path
} catch (e) {}
}
// detect if this is a folder without a trailing slash
if (!isFolder) {
await tryStat(filepath)
if (entry && entry.isDirectory()) {
cleanup()
return respond({
statusCode: 303,
headers: {
Location: `dat://${urlp.host}${urlp.pathname || ''}/${urlp.search || ''}`
},
data: intoStream('')
})
}
}
entry = false
// do actual lookup
if (isFolder) {
await tryStat(filepath + 'index.html')
await tryStat(filepath + 'index.md')
await tryStat(filepath)
} else {
await tryStat(filepath)
await tryStat(filepath + '.html') // fallback to .html
}
// handle folder
if (entry && entry.isDirectory()) {
var cb = once((statusCode, status, contentType, path) => {
const headers = {
'Cache-Control': 'no-cache',
'Content-Type': (contentType || 'text/html; charset=utf-8'),
'Content-Security-Policy': BEAKER_CSP,
'Access-Control-Allow-Origin': '*'
}
if (typeof path === 'string') {
respond({statusCode, headers, data: fs.createReadStream(path)})
} else if (typeof path === 'function') {
respond({statusCode, headers, data: intoStream(path())})
} else {
respond({statusCode, headers, data: intoStream(errorPage(statusCode + ' ' + status))})
}
})
async function serveICO (path, size = 16) {
async upsertIndex(index: Index) {
try {
const currentIndex = await this.getIndex();
const updatedIndex = JSON.stringify({ ...currentIndex, ...index });
const indexStream = intoStream(updatedIndex);
await uploadStreamToBlockBlob(this.aborter, indexStream, this.indexBlobUrl, updatedIndex.length, 10);
} catch (error) {
throw new FailedIndexUpsert(error, index);
}
}
var cb = once((statusCode, status, contentType, path) => {
const headers = {
'Cache-Control': 'no-cache',
'Content-Type': (contentType || 'text/html; charset=utf-8'),
'Content-Security-Policy': BEAKER_CSP,
'Access-Control-Allow-Origin': '*'
}
if (typeof path === 'string') {
respond({statusCode, headers, data: fs.createReadStream(path)})
} else if (typeof path === 'function') {
respond({statusCode, headers, data: intoStream(path())})
} else {
respond({statusCode, headers, data: intoStream(errorPage(statusCode + ' ' + status))})
}
})
async function serveICO (path, size = 16) {
fileReadStream.once('end', () => {
if (!headersSent) {
cleanup()
debug('Served empty file')
respond({
statusCode: 200,
headers: {
'Content-Security-Policy': cspHeader,
'Access-Control-Allow-Origin': '*'
},
data: intoStream('')
})
}
})
const nextStream = () => {
currentIdx += 1;
if (currentIdx === uploads.length) return null;
const chunk = uploads[currentIdx];
if (chunk.bytes) {
return intoStream(chunk.bytes);
} else if (chunk.file) {
return fs.createReadStream(chunk.file);
} else {
throw new Error("not implemented");
}
};
const stream = new StreamConcat(nextStream);
return respond({
statusCode: 303,
headers: {Location: `beaker://library/?view=addressbook&site=${encodeURIComponent(urlp.qs.url)}`},
data: intoStream('')
})
case 'unwalled.garden/view-feed':
return respond({
statusCode: 303,
headers: {Location: `dat://beaker.social/profile/${encodeURIComponent(urlp.qs.url)}`},
data: intoStream('')
})
case 'unwalled.garden/view-file':
return respond({
statusCode: 303,
headers: {Location: `beaker://editor/${urlp.qs.url}`},
data: intoStream('')
})
}
respond({
statusCode: 404,
headers: {'Content-Type': 'text/html; charset=utf-8'},
data: intoStream(errorPage('404 Intent Not Found: ' + urlp.name))
})
}
new Multistream((cb) => {
if (count === 0) {
return cb(undefined, next(
intoStream(binaryBuffer)
));
} else
if (count === 1) {
payloadPosition = meter.bytes;
return cb(undefined, next(
intoStream(Buffer.alloc(0))
));
} else
if (count === 2) {
if (prevStripe && !prevStripe.skip) {
let { snap, store } = prevStripe;
snap = snapshotify(snap, slash);
vfs[snap][store] = [ track, meter.bytes ];
track += meter.bytes;
}
toStream(): NodeJS.ReadableStream {
return intoStream(this.data);
}
}