it('should log CookieLimitExceed error when cookie value too long', done => { const ctx = app.mockContext(); const value = Buffer.alloc(4094).fill(49).toString(); ctx.cookies.set('foo', value); setTimeout(() => { const logPath = path.join(utils.getFilepath('apps/secure-app'), 'logs/secure-app/common-error.log'); const content = fs.readFileSync(logPath, 'utf8'); assert(content.match(/CookieLimitExceedError: cookie foo's length\(4094\) exceed the limit\(4093\)/)); done(); }, 100); });
showLicense(item, focusedWindow) { let options = { title: 'About License', buttons: ['Close'], type: 'info', message: `${Config.license} License`, detail: readFileSync(`${__dirname}/../LICENSE`).toString('utf8') }; dialog.showMessageBox(focusedWindow || null, options); }
app.get( '/notes/:socketId', function( req, res ) { fs.readFile( opts.baseDir + 'plugin/notes-server/notes.html', function( err, data ) { res.send( Mustache.to_html( data.toString(), { socketId : req.params.socketId })); }); });
/** * Encodes the JSON representation of the profile in base64. * * @returns {string} The encoded profile. */ encode() { return Buffer.from(JSON.stringify(this)).toString('base64'); }
async manifestJSON() { const response = await fetch( `https://api.github.com/repos/${this.repo.owner}/${this.repo.name}/contents/manifest.json` ); return JSON.parse(Buffer.from((await response.json()).content, 'base64').toString()); }
const bufferStream = stream => { const chunks = []; return new Promise((resolve, reject) => { stream.on('data', chunk => chunks.push(Buffer.from(chunk))); stream.on('error', reject); stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8'))); }); }
(() => { let result = execSync('npm list --prod --parseable'); return _.chain(result.toString().trim().split(/\r?\n/)) // remove app root path .tap((r) => r.shift()) .filter((dep) => (dep.match(/node_modules/g) || []).length == 1 && !dep.match(/typescript/)) .map((dep) => `${dep}/**/*.{js,cljs,css,json,svg,png,gif,woff2,otf,ttf,woff,eot,ts}`) .value(); })()
readFile('examples/kitchen-sink/data.sql', (error, data) => { if (error) reject(error); else resolve(data.toString().replace(/begin;|commit;/g, '')); });
// Returns a new random hex string of the given even size. function randomHexString(size) { if (size === 0) { throw new Error('Zero-length randomHexString is useless.'); } if (size % 2 !== 0) { throw new Error('randomHexString size must be divisible by 2.'); } return (0, _crypto.randomBytes)(size / 2).toString('hex'); }
constructor(window) { this._window = window; this._info = JSON.parse(Buffer.from(window.paramsForReuse().data, 'base64').toString('utf8')); this._handles = []; this._window.on('close', () => this._handles.splice(0).forEach(handle => handle.dispose())); }
function renderPost (results) { const templateStr = fs.readFileSync(path.resolve(__dirname, 'release.hbs')).toString('utf8') const template = Handlebars.compile(templateStr, { noEscape: true }) const view = Object.assign({ date: new Date().toISOString(), versionSlug: slugify(results.version) }, results) return Object.assign({ content: template(view) }, results) }
const hmacSHA1 = (key: string, data: string) => { // hmac.digest([encoding]) // If encoding is provided a string is returned; otherwise a Buffer is returned; return crypto.createHmac('sha1', key).update(data).digest().toString('base64'); }
// Promisify readFile async function readFile(file) { const promise = await new Promise((resolve, reject) => { fs.readFile(file, (err, data) => { if (err) reject(err); else resolve(data.toString()); }); }); return promise; }
/* * Helper to encode into a base64 string */ const encode = data => { if (_.isObject(data)) data = JSON.stringify(data); return Buffer.from(data).toString('base64'); }
app.get('/app_locals_oom', function*() { for (let i = 0; i < 1000; i++) { app.locals = { // 10MB buff: Buffer.alloc(10 * 1024 * 1024).toString() }; } this.body = 'ok'; });