How to use unzip method in AutoItDriverServer

Best Python code snippet using AutoItDriverServer_python

unzip.js

Source:unzip.js Github

copy

Full Screen

...16var util = require('../util');17var unzipTools = {18 extract: extract19 // expose this function for simple testing20};var unzip = function unzip(_ref) {21 var zipFilePath = _ref.zipFilePath,22 installDir = _ref.installDir,23 progress = _ref.progress;24 debug('unzipping from %s', zipFilePath);25 debug('into', installDir);26 if (!zipFilePath) {27 throw new Error('Missing zip filename');28 }29 var startTime = Date.now();30 var yauzlDoneTime = 0;31 return fs.ensureDirAsync(installDir).then(function () {32 return new Promise(function (resolve, reject) {33 return yauzl.open(zipFilePath, function (err, zipFile) {34 yauzlDoneTime = Date.now();35 if (err) {36 debug('error using yauzl %s', err.message);37 return reject(err);38 }39 var total = zipFile.entryCount;40 debug('zipFile entries count', total);41 var started = new Date();42 var percent = 0;43 var count = 0;44 var notify = function notify(percent) {45 var elapsed = +new Date() - +started;46 var eta = util.calculateEta(percent, elapsed);47 progress.onProgress(percent, util.secsRemaining(eta));48 };49 var tick = function tick() {50 count += 1;51 percent = count / total * 100;52 var displayPercent = percent.toFixed(0);53 return notify(displayPercent);54 };55 var unzipWithNode = function unzipWithNode() {56 debug('unzipping with node.js (slow)');57 var endFn = function endFn(err) {58 if (err) {59 debug('error %s', err.message);60 return reject(err);61 }62 debug('node unzip finished');63 return resolve();64 };65 var opts = {66 dir: installDir,67 onEntry: tick68 };69 debug('calling Node extract tool %s %o', zipFilePath, opts);70 return unzipTools.extract(zipFilePath, opts, endFn);71 };72 var unzipFallback = _.once(unzipWithNode);73 var unzipWithUnzipTool = function unzipWithUnzipTool() {74 debug('unzipping via `unzip`');75 var inflatingRe = /inflating:/;76 var sp = cp.spawn('unzip', ['-o', zipFilePath, '-d', installDir]);77 sp.on('error', function (err) {78 debug('unzip tool error: %s', err.message);79 unzipFallback();80 });81 sp.on('close', function (code) {82 debug('unzip tool close with code %d', code);83 if (code === 0) {84 percent = 100;85 notify(percent);86 return resolve();87 }88 debug('`unzip` failed %o', { code: code });89 return unzipFallback();90 });91 sp.stdout.on('data', function (data) {92 if (inflatingRe.test(data)) {93 return tick();94 }95 });96 sp.stderr.on('data', function (data) {97 debug('`unzip` stderr %s', data);98 });99 };100 // we attempt to first unzip with the native osx101 // ditto because its less likely to have problems102 // with corruption, symlinks, or icons causing failures103 // and can handle resource forks104 // http://automatica.com.au/2011/02/unzip-mac-os-x-zip-in-terminal/105 var unzipWithOsx = function unzipWithOsx() {106 debug('unzipping via `ditto`');107 var copyingFileRe = /^copying file/;108 var sp = cp.spawn('ditto', ['-xkV', zipFilePath, installDir]);109 // f-it just unzip with node110 sp.on('error', function (err) {111 debug(err.message);112 unzipFallback();113 });114 sp.on('close', function (code) {115 if (code === 0) {116 // make sure we get to 100% on the progress bar117 // because reading in lines is not really accurate118 percent = 100;119 notify(percent);120 return resolve();121 }122 debug('`ditto` failed %o', { code: code });123 return unzipFallback();124 });125 return readline.createInterface({126 input: sp.stderr127 }).on('line', function (line) {128 if (copyingFileRe.test(line)) {129 return tick();130 }131 });132 };133 switch (os.platform()) {134 case 'darwin':135 return unzipWithOsx();136 case 'linux':137 return unzipWithUnzipTool();138 case 'win32':139 return unzipWithNode();140 default:141 return;142 }143 });144 }).tap(function () {145 debug('unzip completed %o', {146 yauzlMs: yauzlDoneTime - startTime,147 unzipMs: Date.now() - yauzlDoneTime148 });149 });150 });151};152var start = function start(_ref2) {153 var zipFilePath = _ref2.zipFilePath,154 installDir = _ref2.installDir,155 progress = _ref2.progress;156 la(is.unemptyString(installDir), 'missing installDir');157 if (!progress) {158 progress = { onProgress: function onProgress() {159 return {};160 } };161 }162 return fs.pathExists(installDir).then(function (exists) {163 if (exists) {164 debug('removing existing unzipped binary', installDir);165 return fs.removeAsync(installDir);166 }167 }).then(function () {168 return unzip({ zipFilePath: zipFilePath, installDir: installDir, progress: progress });169 }).catch(throwFormErrorText(errors.failedUnzip));170};171module.exports = {172 start: start,173 utils: {174 unzip: unzip,175 unzipTools: unzipTools176 }...

Full Screen

Full Screen

unzip_spec.js

Source:unzip_spec.js Github

copy

Full Screen

1require('../../spec_helper')2const events = require('events')3const os = require('os')4const path = require('path')5const snapshot = require('../../support/snapshot')6const cp = require('child_process')7const debug = require('debug')('test')8const readline = require('readline')9const fs = require(`${lib}/fs`)10const util = require(`${lib}/util`)11const logger = require(`${lib}/logger`)12const unzip = require(`${lib}/tasks/unzip`)13const stdout = require('../../support/stdout')14const normalize = require('../../support/normalize')15const version = '1.2.3'16const installDir = path.join(os.tmpdir(), 'Cypress', version)17describe('lib/tasks/unzip', function () {18 require('mocha-banner').register()19 beforeEach(function () {20 this.stdout = stdout.capture()21 os.platform.returns('darwin')22 sinon.stub(util, 'pkgVersion').returns(version)23 })24 afterEach(function () {25 stdout.restore()26 // return fs.removeAsync(installationDir)27 })28 it('throws when cannot unzip', function () {29 const ctx = this30 return unzip31 .start({32 zipFilePath: path.join('test', 'fixture', 'bad_example.zip'),33 installDir,34 })35 .then(() => {36 throw new Error('should have failed')37 })38 .catch((err) => {39 logger.error(err)40 snapshot('unzip error 1', normalize(ctx.stdout.toString()))41 })42 })43 it('can really unzip', function () {44 const onProgress = sinon.stub().returns(undefined)45 return unzip46 .start({47 zipFilePath: path.join('test', 'fixture', 'example.zip'),48 installDir,49 progress: { onProgress },50 })51 .then(() => {52 expect(onProgress).to.be.called53 return fs.statAsync(installDir)54 })55 })56 context('on linux', () => {57 beforeEach(() => {58 os.platform.returns('linux')59 })60 it('can try unzip first then fall back to node unzip', function (done) {61 const zipFilePath = path.join('test', 'fixture', 'example.zip')62 sinon.stub(unzip.utils.unzipTools, 'extract').callsFake((filePath, opts, cb) => {63 debug('unzip extract called with %s', filePath)64 expect(filePath, 'zipfile is the same').to.equal(zipFilePath)65 expect(cb, 'has callback').to.be.a('function')66 setTimeout(cb, 10)67 })68 const unzipChildProcess = new events.EventEmitter()69 unzipChildProcess.stdout = {70 on () {},71 }72 unzipChildProcess.stderr = {73 on () {},74 }75 sinon.stub(cp, 'spawn').withArgs('unzip').returns(unzipChildProcess)76 setTimeout(() => {77 debug('emitting unzip error')78 unzipChildProcess.emit('error', new Error('unzip fails badly'))79 }, 100)80 unzip81 .start({82 zipFilePath,83 installDir,84 })85 .then(() => {86 debug('checking if unzip was called')87 expect(cp.spawn, 'unzip spawn').to.have.been.calledWith('unzip')88 expect(unzip.utils.unzipTools.extract, 'extract called').to.be.calledWith(zipFilePath)89 expect(unzip.utils.unzipTools.extract, 'extract called once').to.be.calledOnce90 done()91 })92 })93 it('calls node unzip just once', function (done) {94 const zipFilePath = path.join('test', 'fixture', 'example.zip')95 sinon.stub(unzip.utils.unzipTools, 'extract').callsFake((filePath, opts, cb) => {96 debug('unzip extract called with %s', filePath)97 expect(filePath, 'zipfile is the same').to.equal(zipFilePath)98 expect(cb, 'has callback').to.be.a('function')99 setTimeout(cb, 10)100 })101 const unzipChildProcess = new events.EventEmitter()102 unzipChildProcess.stdout = {103 on () {},104 }105 unzipChildProcess.stderr = {106 on () {},107 }108 sinon.stub(cp, 'spawn').withArgs('unzip').returns(unzipChildProcess)109 setTimeout(() => {110 debug('emitting unzip error')111 unzipChildProcess.emit('error', new Error('unzip fails badly'))112 }, 100)113 setTimeout(() => {114 debug('emitting unzip close')115 unzipChildProcess.emit('close', 1)116 }, 110)117 unzip118 .start({119 zipFilePath,120 installDir,121 })122 .then(() => {123 debug('checking if unzip was called')124 expect(cp.spawn, 'unzip spawn').to.have.been.calledWith('unzip')125 expect(unzip.utils.unzipTools.extract, 'extract called').to.be.calledWith(zipFilePath)126 expect(unzip.utils.unzipTools.extract, 'extract called once').to.be.calledOnce127 done()128 })129 })130 })131 context('on Mac', () => {132 beforeEach(() => {133 os.platform.returns('darwin')134 })135 it('calls node unzip just once', function (done) {136 const zipFilePath = path.join('test', 'fixture', 'example.zip')137 sinon.stub(unzip.utils.unzipTools, 'extract').callsFake((filePath, opts, cb) => {138 debug('unzip extract called with %s', filePath)139 expect(filePath, 'zipfile is the same').to.equal(zipFilePath)140 expect(cb, 'has callback').to.be.a('function')141 setTimeout(cb, 10)142 })143 const unzipChildProcess = new events.EventEmitter()144 unzipChildProcess.stdout = {145 on () {},146 }147 unzipChildProcess.stderr = {148 on () {},149 }150 sinon.stub(cp, 'spawn').withArgs('ditto').returns(unzipChildProcess)151 sinon.stub(readline, 'createInterface').returns({152 on: () => {},153 })154 setTimeout(() => {155 debug('emitting ditto error')156 unzipChildProcess.emit('error', new Error('ditto fails badly'))157 }, 100)158 setTimeout(() => {159 debug('emitting ditto close')160 unzipChildProcess.emit('close', 1)161 }, 110)162 unzip163 .start({164 zipFilePath,165 installDir,166 })167 .then(() => {168 debug('checking if unzip was called')169 expect(cp.spawn, 'unzip spawn').to.have.been.calledWith('ditto')170 expect(unzip.utils.unzipTools.extract, 'extract called').to.be.calledWith(zipFilePath)171 expect(unzip.utils.unzipTools.extract, 'extract called once').to.be.calledOnce172 done()173 })174 })175 })...

Full Screen

Full Screen

UnZipTerrainData.js

Source:UnZipTerrainData.js Github

copy

Full Screen

1/**2 * Cesium - https://github.com/AnalyticalGraphicsInc/cesium3 *4 * Copyright 2011-2017 Cesium Contributors5 *6 * Licensed under the Apache License, Version 2.0 (the "License");7 * you may not use this file except in compliance with the License.8 * You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * distributed under the License is distributed on an "AS IS" BASIS,14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15 * See the License for the specific language governing permissions and16 * limitations under the License.17 *18 * Columbus View (Pat. Pend.)19 *20 * Portions licensed separately.21 * See https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md for full licensing details.22 */23define(['./when-8d13db60', './createTaskProcessorWorker', './pako_inflate-8ea163f9', './unzip-b0fc9445'], function (when, createTaskProcessorWorker, pako_inflate, unzip) { 'use strict';24 var unzipwasmReady = false;25 unzip.unzip.onRuntimeInitialized = function() {26 unzipwasmReady = true;27 };28 var unzipwasm = unzip.unzip.cwrap('unzip', 'number', ['number', 'number', 'number', 'number']);29 var freec = unzip.unzip.cwrap('freePointer', null, ['number']);30 function unzipWithwasm(datazip) {31 var unzipsize = datazip.length * 4;32 var offset = unzip.unzip._malloc(Uint8Array.BYTES_PER_ELEMENT * unzipsize); //开辟内存33 var tar = new Uint8Array(unzipsize);34 unzip.unzip.HEAPU8.set(tar, offset / Uint8Array.BYTES_PER_ELEMENT);35 var offset1 = unzip.unzip._malloc(Uint8Array.BYTES_PER_ELEMENT * datazip.length);36 unzip.unzip.HEAPU8.set(datazip, offset1 / Uint8Array.BYTES_PER_ELEMENT);37 var resultLen;38 while ((resultLen = unzipwasm(offset, unzipsize, offset1, datazip.length)) == 0) {39 freec(offset); //释放内存40 unzipsize *= 4;41 offset = unzip.unzip._malloc(Uint8Array.BYTES_PER_ELEMENT * unzipsize);42 tar = new Uint8Array(unzipsize);43 unzip.unzip.HEAPU8.set(tar, offset / Uint8Array.BYTES_PER_ELEMENT);44 }45 var res = new Uint8Array(unzip.unzip.HEAPU8.buffer, offset, resultLen);46 datazip = null;47 tar = null;48 var buffer = new Uint8Array(res);49 freec(offset);50 freec(offset1);51 return buffer;52 }53 function UnZipTerrainData(parameters, transferableObjects) {54 var buffer = parameters.data;55 var dataZip = new Uint8Array(buffer);56 var unzipBuffer;57 if (unzipwasmReady === true) {58 unzipBuffer = unzipWithwasm(dataZip);59 return {60 data : unzipBuffer61 };62 } else {63 unzipBuffer = pako_inflate.pako.inflate(dataZip).buffer;64 }65 66 transferableObjects.push(unzipBuffer);67 return {68 data : new Uint8Array(unzipBuffer)69 };70 }71 var UnZipTerrainData$1 = createTaskProcessorWorker(UnZipTerrainData);72 return UnZipTerrainData$1;...

Full Screen

Full Screen

defines_11.js

Source:defines_11.js Github

copy

Full Screen

1var searchData=2[3 ['unz_5fbadpassword',['UNZ_BADPASSWORD',['../unzip_8h.html#ae8fdd0cac39afcff5ede7699dc7fb626',1,'unzip.h']]],4 ['unz_5fbadzipfile',['UNZ_BADZIPFILE',['../unzip_8h.html#a3fcc1d41cbea304ce10286ce99577625',1,'unzip.h']]],5 ['unz_5fbufsize',['UNZ_BUFSIZE',['../unzip_8c.html#ac88907609a3408a8ee6544287b6c9880',1,'unzip.c']]],6 ['unz_5fcrcerror',['UNZ_CRCERROR',['../unzip_8h.html#ae9155f504a5db40587b390f9e487c303',1,'unzip.h']]],7 ['unz_5fend_5fof_5flist_5fof_5ffile',['UNZ_END_OF_LIST_OF_FILE',['../unzip_8h.html#ac55ed190d07021ce9bc1bf34b91dcae9',1,'unzip.h']]],8 ['unz_5feof',['UNZ_EOF',['../unzip_8h.html#a0438887aea4e1c58e1b3955838a907f3',1,'unzip.h']]],9 ['unz_5ferrno',['UNZ_ERRNO',['../unzip_8h.html#aae99fb3e34ea9f78ca8ba4a716f86e68',1,'unzip.h']]],10 ['unz_5finternalerror',['UNZ_INTERNALERROR',['../unzip_8h.html#a813da146afcb179d57e948bf6871799b',1,'unzip.h']]],11 ['unz_5fmaxfilenameinzip',['UNZ_MAXFILENAMEINZIP',['../unzip_8c.html#a97ef86322b25dcc3d0fc5eb50d386b54',1,'unzip.c']]],12 ['unz_5fok',['UNZ_OK',['../unzip_8h.html#ada043545f95ccd4dae93fa44d95e39a8',1,'unzip.h']]],13 ['unz_5fparamerror',['UNZ_PARAMERROR',['../unzip_8h.html#aca983831f4d25e504d544eb07f48e39b',1,'unzip.h']]],14 ['use_5fsearch1',['USE_SEARCH1',['../matching_8c.html#a60cd0167c898fa5099644f1e5ad0b4db',1,'USE_SEARCH1(): matching.c'],['../matching2_8c.html#a60cd0167c898fa5099644f1e5ad0b4db',1,'USE_SEARCH1(): matching2.c']]],15 ['use_5fsearch2',['USE_SEARCH2',['../matching_8c.html#ac1e3392a6d92afa6cc2ac8468f5055ef',1,'USE_SEARCH2(): matching.c'],['../matching2_8c.html#ac1e3392a6d92afa6cc2ac8468f5055ef',1,'USE_SEARCH2(): matching2.c']]],16 ['use_5fsearch3',['USE_SEARCH3',['../matching_8c.html#aafbcf2646f3e630088e750fd3ee816db',1,'USE_SEARCH3(): matching.c'],['../matching2_8c.html#aafbcf2646f3e630088e750fd3ee816db',1,'USE_SEARCH3(): matching2.c']]]...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run AutoItDriverServer automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful