List the contents of a tar file using javascript - javascript

I have a jsp file in which i am writing a function in javascript that takes as argument, a tar file name and returns a list of the file names of the files that the tar file contains.. How can it be done?

Have you tried using UnTar.js ? Its open source js library for that
edit :
providing usage example for clarity
function updateProgressBar(e) { ... update UI element ... }
function displayZipContents(e) { ... display contents of the file ... }
var unzipper = new bitjs.archive.Unzipper(zipFileArrayBuffer);
unzipper.addEventListener("progress", updateProgressBar);
unzipper.addEventListener("finish", displayZipContents);
unzipper.start();
some more info here

Related

How to add html file into different js folder

pic
I want to add html file in my js, and this pic is the path in my directory. How can I do?
in my config.js, I widh to include my file as let ADDR_iframe1 = "../templates/switch.html";
Use JavaScript fetch() Method to Load an External HTML File.
Please find the below example for your reference.
function loadHTML() {
fetch('switch.html')
.then(response=> response.text())
.then(text=> document.getElementById('xyz').innerHTML = text);
}

Running a script on all .ai files in a directory

I'm a graphic designer and a beginner at coding. So please dumb down for me :)
I have a script that I run through Illustrator. It embeds an image and removes a clipping mask on the file. I need this script to run on multiple .ai files in a folder.
The thing is, I cannot create a batch action (in Illustrator) to run the script. Our IT guy doesn't want to add the script to our Illustrator settings on multiple accounts. Is there a way to add code to my script to do this?
I need it to open all the files, run the script and save. The files can be left open on Illustrator, no need to close.
What code do I need to add to my script?
I am on a Mac not PC.
It can be done this way:
function my_script() {
// copy a full text of your script here
// or include the jsx file this way:
# include '~/Desktop/script/my_script.jsx'
}
function main() {
var folder = Folder.selectDialog('Please, select the folder');
if (!(folder instanceof Folder)) return;
var files = folder.getFiles('*.ai');
if (files.length == 0) {
alert('Folder doesn\'t content AI files');
return;
}
var i = files.length;
while (i--) {
var doc = app.open(files[i]);
my_script(); // <------- here your script is running
doc.save();
doc.close();
}
alert(files.length + ' files were processed');
}
main();
If you have subfolders with .ai files inside your chosen folder and you need to access them in the script, you may find this JS snippet useful as well:
https://gist.github.com/joonaspaakko/df2f9e31bdb365a6e5df

Mustache.js - using partial inside an external template file

I'm using external template file and I want to use a partial inside the template file (.mst file inside another .mst file)
For example I have template.mst file with this code:
{{#comments}}
// Here I want to use another external .mst file
{{/comments}}
So I careated a comment.mst file beside the template.mst file and now I'm trying to use {{>comment}} to call this external template file - full example:
{{#comments}}
{{>comment}}
{{/comments}}
But it doesn't work. I tried to play with it a little bit, I tried to add the file extension {{>comment.mst}} and I tried to add the path {{>temmplates/comment}} and any pther option.
This is the code I use to load the template:
$.get('templates/template.mst', function(template) {
var rendered = Mustache.render(template, postData);
$('.inner-container').prepend(rendered);
});
I guess I missing something, Can someone give me an hint? Thanks!

Dumping Source Code into a local file using CasperJS

When I use download() in CasperJS, I get a file saved in the system, but the file doesn't contain the actual source code of the webpage. It just contains a link to the remote page. How can I dump the source code of webpage into a local file using CasperJs? getHTML() is also only echoing the contents onto the terminal. How to save the contents to a file?
First import file system library
var fs = require('fs');
Extract html
var html = this.getHTML();
// or
var html = this.getPageContent();
Copy into a file
var f = fs.open('/path/to/your/file', 'w');
f.write(html);
f.close();
do just: fs.write('path/to/file', 'your string', 'w');
in this case you don't need open and close a file

AJAX read javascript file as text file (prevent code repeated)

How to read javascript file as text file and prevent code to run multiple time
index.js
version = "1.001";
alert("JS run");
... other code ...
and I have html that use index.js
I try to read index.js by using
jQuery.get("js/index.js",function(data){
var currentVersion = data.split("\n")[0].split('"')[1];
}
I can read text as I want but alert("JS run") and other code inside also run after I use this code.

Categories