/** * Determine which Photon server to connect to: `i0`, `i1`, or `i2`. * * Statically hash the subdomain based on the URL, to optimize browser caches. * @param {string} pathname The pathname to use * @return {string} The hostname for the pathname */ function serverFromPathname( pathname ) { var hash = crc32(pathname); var rng = seed(hash); var server = 'i' + Math.floor(rng() * 3); debug('determined server "%s" to use with "%s"', server, pathname); return server + '.wp.com'; }
/* * ZIPs a file in GZIP format. The format is as given by the spec, found at: * http://www.gzip.org/zlib/rfc-gzip.html * * Omitted parts in this implementation: */ function zip(data, options) { var flags = 0, level, crc, out = []; if (!options) { options = {}; } level = options.level || DEFAULT_LEVEL; if (typeof data === 'string') { data = Array.prototype.map.call(data, function (char) { return char.charCodeAt(0); }); } // magic number marking this file as GZIP putByte(ID1, out); putByte(ID2, out); putByte(compressionMethods['deflate'], out); if (options.name) { flags |= possibleFlags['FNAME']; } putByte(flags, out); putLong(options.timestamp || parseInt(Date.now() / 1000, 10), out); // put deflate args (extra flags) if (level === 1) { // fastest algorithm putByte(4, out); } else if (level === 9) { // maximum compression (fastest algorithm) putByte(2, out); } else { putByte(0, out); } // OS identifier putByte(osMap[os], out); if (options.name) { // ignore the directory part putString(options.name.substring(options.name.lastIndexOf('/') + 1), out); // terminating null putByte(0, out); } deflate.deflate(data, level).forEach(function (byte) { putByte(byte, out); }); putLong(parseInt(crc32(data), 16), out); putLong(data.length, out); return out; }
file.read(function (err, string) { if (err) return done(err); var hash = file.filename + '#' + calculate(string); var res; try { res = cache[hash] = cache[hash] || cs.compile(string, options); } catch (err) { done(err); return; } // have any future plugin treat this string as JS file.extension = 'js'; // rewrite source map var map = JSON.parse(res.v3SourceMap); map.sources[0] = file.filename; map.sourcesContent = [string]; file.string = res.js; file.sourceMap = JSON.stringify(map); file.originalString = string; // why not done(); })
function getMultipart(uptoken, key, body, extra) { var form = formstream(); form.field('token', uptoken); if(key != exports.UNDEFINED_KEY) { form.field('key', key); } form.buffer('file', new Buffer(body), key, extra.mimeType); //extra['checkcrc'] if (extra.checkCrc == 1) { var bodyCrc32 = getCrc32(body); extra.crc32 = '' + parseInt(bodyCrc32, 16); } if(extra.checkCrc) { form.field('crc32', extra.crc32); } for (var k in extra.params) { form.field(k, extra.params[k]); } return form; }
function append(notification, list) { const id = notification.id || crc32(notification.text + notification.url).toString(36); if (list.find((n) => n.id === id)) { return list; } return [{id, ...notification}, ...list]; }
Object.keys(tests).forEach(function (key) { label = "\t" + key; console.time(label); for (var i = 0; i < N; i++) { crc = js_crc32(tests[key], true); } console.timeEnd(label); });
/** * @internal * * Sanitizes a stringified GraphQL field (including any calls and their values) * to produce a valid alias. * * This is used to auto-alias fields in generated queries, so that developers * composing multiple components together don't have to worry about collisions * between components requesting the same fields. (Explicit aliases are only * needed within a single component when it uses the same field multiple times, * in order to differentiate these fields in the props). */ function generateRQLFieldAlias(input: string): string { // Field names with no calls can be used as aliases without encoding var index = input.indexOf('.'); if (index === -1) { return input; } // Unsign crc32 hash so we do not base62 encode a negative number. return PREFIX + input.substr(0, index) + base62(crc32(input) >>> 0); }
var objects = offsetOrder.map(function(index, i) { var nextIndex = offsetOrder[i + 1]; var interOffsetLength = (nextIndex ? nextIndex.offset : buffer.length - 20) - index.offset; if (parseInt(index.checksum, 16) != parseInt(crc32(buffer.slice(index.offset, index.offset + interOffsetLength)), 16)) { console.log(index.checksum, crc32(buffer.slice(index.offset, index.offset + interOffsetLength))); throw "Checksum failure"; } if (index.offset != reader.bytesRead()) { console.log(index.offset, reader.bytesRead()) throw "I've lost my place, sad face..."; } var header = readPackedObjectHeader(reader); var object = { index: index, header: header }; if (header.type == 'ofsDelta') { var offset = readVariableLengthOffset(reader); reader.inflate(interOffsetLength - header.headerLength - offset.headerLength, function(error) { if (error) throw error; }); } else if (header.type == 'refDelta') { // none of these in sample data object.reference = reader.readSha1(); reader.inflate(header.size, function(error) { if (error) throw error; }); } else { reader.inflate(interOffsetLength - header.headerLength, function(error, buffer) { if (error) { console.log(index.hash, header, offsetOrder.slice(0, i + 1)); throw error; } // if (header.type == 'commit') { // console.log(buffer.toString('utf8')); // } }); } return object; });
fs.readFile(path.join("./src-templates", file.templateFileName), 'utf8', function(err, data) { if(err) { throw err; } var output = Mustache.compile(data, { space: true })(ctx, null); var outputFilename = path.join("./src-generated", ctx.outputFilename); var oldContentsCrc = 0; if(path.existsSync(outputFilename)) { var oldContents = fs.readFileSync(outputFilename, 'utf8'); oldContentsCrc = crc32(oldContents); } var newContentsCrc = crc32(output); if(oldContentsCrc != newContentsCrc) { fs.writeFile(outputFilename, output, callback); } else { console.log(yellow("skipping " + ctx.outputFilename + " crc match")); callback(); } });
var Chunk = function (type, payload) { 'use strict'; if (typeof(type) === "string") type = new Buffer(type); if (!payload) payload = new Buffer(0); return Buffer.concat([ new Buffer( hex(payload.length, 8), 'hex'), type, payload, new Buffer( hex(crc32( Buffer.concat([type, payload], type.length + payload.length) ), 8), 'hex' ) ]); };
sendImpl(method: ?string, url: ?string, headers: Object, data: any): void { RCTDataManager.queryData( 'http', JSON.stringify({ method: method, url: url, data: data, headers: headers, }), 'h' + crc32(method + '|' + url + '|' + data), (result) => { result = JSON.parse(result); this.callback(result.status, result.responseHeaders, result.responseText); } ); }
sendImpl(method: ?string, url: ?string, headers: Object, data: any): void { RCTDataManager.queryData( 'http', { method: method, url: url, data: data, headers: headers, }, // TODO: Do we need this? is it used anywhere? 'h' + crc32(method + '|' + url + '|' + data), (result) => { result = JSON.parse(result); this.callback(result.status, result.responseHeaders, result.responseText); } ); }
} endTime = process.hrtime(startTime); console.log('\tHardware-based CRC-32C: %d ms', (endTime[0] * 1e9 + endTime[1]) / (1000 * 1000)); // Software-based CRC-32C startTime = process.hrtime(); for (i = 0; i < INVOCATIONS; i++) { crc = Sse4Crc32.calculateInSoftware(TEST_BUFFER); } endTime = process.hrtime(startTime); console.log('\tSoftware-based CRC-32C: %d ms', (endTime[0] * 1e9 + endTime[1]) / (1000 * 1000)); // Pure JS CRC-32C (table-based) startTime = process.hrtime(); for (i = 0; i < INVOCATIONS; i++) { crc = jsCrc32(TEST_BUFFER, false); } endTime = process.hrtime(startTime); console.log('\tPure JS CRC-32C (table-based): %d ms', (endTime[0] * 1e9 + endTime[1]) / (1000 * 1000)); // Pure JS CRC-32C (direct) startTime = process.hrtime(); for (i = 0; i < INVOCATIONS; i++) { crc = jsCrc32(TEST_BUFFER, true); } endTime = process.hrtime(startTime); console.log('\tPure JS CRC-32C (direct): %d ms', (endTime[0] * 1e9 + endTime[1]) / (1000 * 1000));
function unzip(data, options) { // start with a copy of the array var arr = Array.prototype.slice.call(data, 0), t, compressionMethod, flags, mtime, xFlags, key, os, crc, size, res; // check the first two bytes for the magic numbers if (readByte(arr) !== ID1 || readByte(arr) !== ID2) { throw 'Not a GZIP file'; } t = readByte(arr); t = Object.keys(compressionMethods).some(function (key) { compressionMethod = key; return compressionMethods[key] === t; }); if (!t) { throw 'Unsupported compression method'; } flags = readByte(arr); mtime = readLong(arr); xFlags = readByte(arr); t = readByte(arr); Object.keys(osMap).some(function (key) { if (osMap[key] === t) { os = key; return true; } }); // just throw away the bytes for now if (flags & possibleFlags['FEXTRA']) { t = readShort(arr); readBytes(arr, t); } // just throw away for now if (flags & possibleFlags['FNAME']) { readString(arr); } // just throw away for now if (flags & possibleFlags['FCOMMENT']) { readString(arr); } // just throw away for now if (flags & possibleFlags['FHCRC']) { readShort(arr); } if (compressionMethod === 'deflate') { // give deflate everything but the last 8 bytes // the last 8 bytes are for the CRC32 checksum and filesize res = deflate.inflate(arr.splice(0, arr.length - 8)); } if (flags & possibleFlags['FTEXT']) { res = Array.prototype.map.call(res, function (byte) { return String.fromCharCode(byte); }).join(''); } crc = readLong(arr); if (crc !== parseInt(crc32(res), 16)) { throw 'Checksum does not match'; } size = readLong(arr); if (size !== res.length) { throw 'Size of decompressed file not correct'; } return res; }
samples.forEach(sample => { expect(crc32(sample.input)).toBe(sample.output); });
module.exports = function underscored_crc32 (pattern) { pattern = normalized(pattern) var underscored = underscore(pattern) var crc = crc32(pattern.length + ':' + pattern).toString(16) return underscored + '_' + crc }
* Copyright (c) 2013-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule generateClientID * @typechecks */ 'use strict'; const crc32 = require('crc32'); const performanceNow = require('performanceNow'); let _clientID = 1; const _prefix = 'client:' + crc32('' + performanceNow()); /** * Generate a unique clientID for GraphQL data objects that do not already have * an ID or their ID = null * * @internal */ function generateClientID() { return _prefix + _clientID++; } module.exports = generateClientID;
function _createCID() { return crc32((++_i) + "." + Date.now() + "." + (Math.round(Math.random() * 999999))); }
fsStream.on('end', function() { fileBody = Buffer.concat(fileBody); var bodyCrc32 = parseInt('0x' + getCrc32(fileBody)); postForm.field('crc32', bodyCrc32); });