Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@applitools/screenshoter

Package Overview
Dependencies
Maintainers
30
Versions
173
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@applitools/screenshoter - npm Package Compare versions

Comparing version 3.3.22 to 3.3.23

7

package.json
{
"name": "@applitools/screenshoter",
"version": "3.3.22",
"version": "3.3.23",
"description": "Applitools universal screenshoter for web and native applications",

@@ -38,3 +38,3 @@ "keywords": [

"test:it": "mocha ./test/it/*.spec.js --no-timeouts",
"test:e2e": "yarn test:e2e:web && yarn && test:e2e:android && yarn test:e2e:ios",
"test:e2e": "yarn test:e2e:web && yarn && yarn test:e2e:android && yarn test:e2e:ios",
"test:e2e:web": "mocha ./test/e2e/web/*.spec.js --no-timeouts -r @applitools/test-utils/mocha-hooks/docker",

@@ -67,2 +67,3 @@ "test:e2e:android": "APPLITOOLS_TEST_REMOTE=sauce mocha ./test/e2e/android*/*.spec.js --no-timeouts --parallel --jobs ${MOCHA_JOBS:-2}",

"@applitools/utils": "1.3.0",
"jpeg-js": "0.4.3",
"png-async": "0.9.4"

@@ -72,3 +73,3 @@ },

"@applitools/bongo": "^2.0.3",
"@applitools/driver": "^1.8.12",
"@applitools/driver": "^1.8.13",
"@applitools/scripts": "1.1.0",

@@ -75,0 +76,0 @@ "@applitools/spec-driver-webdriverio": "1.2.9",

@@ -5,2 +5,3 @@ const fs = require('fs')

const png = require('png-async')
const jpeg = require('jpeg-js')
const utils = require('@applitools/utils')

@@ -13,12 +14,15 @@

if (utils.types.isBase64(data)) {
const buffer = Buffer.from(data, 'base64')
image = fromBuffer(buffer)
size = extractPngSize(buffer)
return makeImage(Buffer.from(data, 'base64'))
} else if (utils.types.isString(data)) {
const buffer = fs.readFileSync(data)
image = fromBuffer(buffer)
size = extractPngSize(buffer)
return makeImage(fs.readFileSync(data))
} else if (Buffer.isBuffer(data)) {
image = fromBuffer(data)
size = extractPngSize(data)
if (isPngBuffer(data)) {
image = fromPngBuffer(data)
size = extractPngSize(data)
} else if (isJpegBuffer(data)) {
image = fromJpegBuffer(data)
size = extractJpegSize(data)
} else {
throw new Error('Unable to create an image abstraction from buffer with unknown data')
}
} else if (data.isImage) {

@@ -163,8 +167,30 @@ transforms = data.transforms

function extractPngSize(buffer) {
function isPngBuffer(buffer) {
return buffer.slice(12, 16).toString('ascii') === 'IHDR'
? {width: buffer.readUInt32BE(16), height: buffer.readUInt32BE(20)}
: {width: 0, height: 0}
}
function isJpegBuffer(buffer) {
return buffer.slice(6, 10).toString('ascii') === 'JFIF'
}
function extractPngSize(buffer) {
return {width: buffer.readUInt32BE(16), height: buffer.readUInt32BE(20)}
}
function extractJpegSize(buffer) {
// skip file signature
let offset = 4
while (buffer.length > offset) {
// extract length of the block
offset += buffer.readUInt16BE(offset)
// if next segment is SOF extract size
if (buffer[offset + 1] === 0xc0) {
return {width: buffer.readUInt16BE(offset + 7), height: buffer.readUInt16BE(offset + 5)}
} else {
// skip block signature
offset += 2
}
}
}
function fromSize(size) {

@@ -174,3 +200,3 @@ return new png.Image({width: size.width, height: size.height})

async function fromBuffer(buffer) {
async function fromPngBuffer(buffer) {
return new Promise((resolve, reject) => {

@@ -186,2 +212,6 @@ const image = new png.Image()

async function fromJpegBuffer(buffer) {
return jpeg.decode(buffer, {tolerantDecoding: true, formatAsRGBA: true})
}
async function toPng(image) {

@@ -188,0 +218,0 @@ return new Promise((resolve, reject) => {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc