Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
finish() {
log.debug("Finished packing.")
const buf = readFileSync(pathResolve(cwd, ".fly/bundle.tar"))
console.log(`Bundle size: ${buf.byteLength / (1024 * 1024)}MB`)
const gz = pako.gzip(buf)
console.log(`Bundle compressed size: ${gz.byteLength / (1024 * 1024)}MB`)
const bundleHash = createHash("sha1") // we need to verify the upload is :+1:
bundleHash.update(buf)
API.post(`/api/v1/apps/${appName}/releases`, gz, {
params: {
sha1: bundleHash.digest("hex"),
env
},
headers: {
"Content-Type": "application/x-tar",
"Content-Length": gz.byteLength,
"Content-Encoding": "gzip"
},
maxContentLength: 100 * 1024 * 1024,
timeout: 120 * 1000
// See if any options have been set
if (options !== undefined && options !== null) {
logger.info("test: " + options.algorithm);
// Check algorithm
if (options['algorithm']) {
logger.info("test");
algorithm = options['algorithm'];
}
}
if (algorithm === null || algorithm.toUpperCase() === "DEFLATE") {
logger.debug("Compressing with DEFLATE!");
resultPayload.body = pako.deflate(payload);
} else if (algorithm.toUpperCase() === "GZIP") {
logger.debug("Compressing with GZIP");
resultPayload.body = pako.gzip(payload);
} else {
throw new Error("Unknown or unsupported algorithm " + algorithm);
}
// Create and add the algorithm metric if is has been specified in the options
if (algorithm !== null) {
resultPayload.metrics = [ {
"name" : "algorithm",
"value" : algorithm.toUpperCase(),
"type" : "string"
} ];
}
return resultPayload;
},
body.append('user_agent', userAgent);
if (client) {
body.append('user_id', client.credentials.userId);
body.append('device_id', client.deviceId);
}
if (opts.sendLogs) {
progressCallback(_t("Collecting logs"));
const logs = await rageshake.getLogsForReport();
for (const entry of logs) {
// encode as UTF-8
const buf = new TextEncoder().encode(entry.lines);
// compress
const compressed = pako.gzip(buf);
body.append('compressed-log', new Blob([compressed]), entry.id);
}
}
progressCallback(_t("Uploading report"));
await _submitReport(bugReportEndpoint, body, progressCallback);
}
logger.debug("Compressing payload " + JSON.stringify(options));
// See if any options have been set
if (options !== undefined && options !== null) {
// Check algorithm
if (options['algorithm']) {
algorithm = options['algorithm'];
}
}
if (algorithm === null || algorithm.toUpperCase() === "DEFLATE") {
logger.debug("Compressing with DEFLATE!");
resultPayload.body = pako.deflate(payload);
} else if (algorithm.toUpperCase() === "GZIP") {
logger.debug("Compressing with GZIP");
resultPayload.body = pako.gzip(payload);
} else {
throw new Error("Unknown or unsupported algorithm " + algorithm);
}
// Create and add the algorithm metric if is has been specified in the options
if (algorithm !== null) {
resultPayload.metrics = [ {
"name" : "algorithm",
"value" : algorithm.toUpperCase(),
"type" : "string"
} ];
}
return resultPayload;
},
async encode(config: Config): Promise {
const configStr = JSON.stringify(config);
const gziped: Uint8Array = gzip(configStr);
const base64String = btoa(String.fromCharCode(...gziped));
return encodeURIComponent(base64String);
}
}
var uploadImgToS3 = (file, filename, imgType) => {
var body = file
if (imgType === 'image/svg+xml') {
body = pako.gzip(file)
}
return new Promise((resolve, reject) => {
credsRef.once('value', snapshot => {
var creds = snapshot.val()
AWS.config.credentials = {
accessKeyId: creds.s3AccessKey,
secretAccessKey: creds.s3SecretKey}
var params = {
Bucket: s3BucketName,
Key: filename,
ACL: 'public-read',
CacheControl: 'max-age: 45792000',
ContentType: imgType,
Body: body}
if (imgType === 'image/svg+xml') {
_sendGzip(data, result) {
this.transactions[data.id] = result
this.ws.send(pako.gzip(JSON.stringify(data)))
}
closeBlaze() {
public static toBase64(object: T): string {
return btoa(gzip(JSON.stringify(object), {to: "string"}));
}
const upload = ({ appName, stage }) => {
const bundle = fs.readFileSync(
path.resolve(process.cwd(), '.fly/bundle.tar')
);
const gzippedBundle = pako.gzip(bundle);
const bundleHash = createHash('sha1').update(bundle);
return flyAxios.post(`/api/v1/apps/${appName}/releases`, gzippedBundle, {
params: {
sha1: bundleHash.digest('hex'),
env: stage,
},
headers: {
'Content-Type': 'application/x-tar',
'Content-Length': gzippedBundle.byteLength,
'Content-Encoding': 'gzip',
},
maxContentLength: 100 * 1024 * 1024,
timeout: 120 * 1000,
});
};