I want to create torrent files with a Firefox extension written using javascript.
Torrent file creators are currently available as desktop applications in anything but javascript.
May be it is also possible to find a decent torrent file spec in java, as azurious, an open source p2p client, is written in java.
Can somebody please give me hints, or maybe some specs, to achieve it using javascript.
Javascript is normally run within a browser in a "sandboxed" environment, where it can't for example create files. If you want to use Javascript in a standalone environment, such as jslibs, that's a very different proposition, and creating files becomes possible. So is your issue with Javascript per se, as your question and tagging indicate, or with the sandboxing browsers typically perform on it?
Related
I have found a couple of libraries that allow to generate/edit/read PDFs in javascript like jsPDF, Mozzila's pdf.js.
And these were present before the advent of ES6 or HTML5. So no modern technologies were present.
I want to understand from a JS perspective how these libraries have achieved to do this? As far as I understand PDF file/format/container is Proprietary having Open SDKs for different languages which are then used by Softwares, like the one MS Word may use for converting DOC to PDF.
An SDK for JS seems unlikely since the whole code runs on the client side and does not support interfacing with binaries of other languages. So how would one actually create a pdf file in JS which runs in the browsers' js compiler. Looking at the libraries it seems that is what they have done.
Julien Viereck has a great youtube video online explaining how pdf.js works internally.
https://www.youtube.com/watch?v=Iv15UY-4Fg8
You can also browse the PDF.js codebase to learn more (https://github.com/mozilla/pdf.js/).
There's nothing inherently special about a PDF file that prevents it from being created by anything that can write text and binary to a file. The object definitions can become quite complex but it's still just a matter of conforming to the specification.
It's all laid out in the PDF Reference.
Is it possible with Javascript or jQuery to convert mp3, wav, etc. to m4r format?
Let's assume you had a library that can change the format of files.
Let's also assume you only need the application to work on current browsers that implement FileAPI or FileReference so you can have access to uploaded files (you can't have access to them without FileAPI or FileReference unless you use Flash or Java Applets or equivalent technologies).
You wouldn't be able to write the output file back to the user because JavaScript is not allowed to access the local filesystem.
Your only solution would become sending the converted file to the server and the server sending it back to you with a force download directive so that the user will be prompted to download the results.
Now back to if there were a library that can the conversion (or even native JavaScript)... I haven't heard of any. It's not impossible to build one but it is impractical and wouldn't run very fast.
Edit:
Let's not forget Node.js!
It's a backend server that uses Google Chrome's V8 JavaScript interpretor/compiler. And it runs JavaScript as a backend scripting engine.
You have access to filesystem, databases and everything if you use that (or any other backend system for that matter) and still be using JavaScript. You can use libraries too. Either written in JavaScript or libraries written in other languages that have been linked to interface with Node.js.
Edit 2:
There is a PC emulator written entirely in JavaScript. It runs binary executables if you want it to. It's called JSLinux.
If you're feeling particularly rambunctious you can grab the ffmpeg binary executable (compiled with static linking). And embed it into your application code as an uuencoded string then use JSLinux to execute the commands and grab the results.
Indeed, it is possible doing this on the client using the latest js technologies. A web-worker thread can do the work in the background. At least in Firefox and Chrome it is also possible to read ("upload in memory") and write ("download from memory") files using the new W3C File API, see here.
I managed to read files via drag&drop from and within the client using google's GWT which in the end is plain javascript, so it must also be possible to do it "natively".
Besides that, the conversation algorithm of course has to be implemented in a javascript web worker to avoid blocking the gui. This should be the hardest part, but not impossible, though.
You would need a backend to do this. You may want to look into the PHPExtension of FFmpeg
Trying to see if this is possible -
1.) User logs into our site
2.) Points to a directory
3.) The javascript code reads contents of the directory, shows thumbnails for any jpeg/gif in those directories. This all without uploading all the photos to the server. Kind of a semi desktop app.
Point 3 is something I have never done, is this possible for an online application to do ?
You can't do this...yet (unless you're using a prerelease of Chrome 9). There are some APIs coming down the pike that will make this possible in browsers that support them; there's a description of using them in this article.
But right now, no. To do this, you'll need to use a technology that allows local file access, such as a signed Java applet (normal unsigned ones obviously can't do this) or, on a severely limited number of platforms and browsers, an ActiveX control.
Update: Sorry, the new JavaScript APIs I mentioned above don't give you (user-granted) access to any old directory on their system. They do give you access to the file system, but it's a sandboxed file system. So you'd have to have the users move the files into the sandbox (which you could do via the File API and with drag-and-drop, keeping it an entirely client-side thing, no uploading required). But that isn't quite what you described.
No; this is not possible.
Javascript cannot directly interact with the user's local filesystem
No, it is not possible to access any of the clients files using JavaScript as that would be a security risk.
I started learning JavaScript a while ago. It's a fairly easy programming language considering that I learned Java in university, that I know php pretty well and that I already played around with python and ruby. The problem is that to properly learn a programming language I usually create a project. In javascript, I just don't know what kind of project I could create - that is, a project that is not web-based or related to the web browser. Can I create javascript shell scripts? Where is javascript commonly used beside the web browsers?
So, can someone actually give me some ideas please?
Can I create javascript shell scripts?
You bet!
On Windows, you can do this by using cscript.exe (you can even set up a file extension -- I use jx -- that automatically runs when you just double-click the filename or use it as a command in a shell: Just associate that file extension with the command "c:\WINDOWS\system32\cscript.exe" /e:JavaScript /nologo "%1" %*). This is (and I've measured carefully) about 80 milion times better than fighting with Windows' batch language. About. (And if you don't want to use JScript — Microsoft's variant of JavaScript — you even have options, see below.)
On *nix, a shell script can be set to run in any installed interpreter (that's what the #!... line at the top is telling the command interpreter). I expect you'll find a few if you search around.
On the Mac, you probably have JavaScriptCore installed in /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc
And on all of the above, if you like, you can install Rhino and Java and get platform independence and access to a huge range of library functionality. Rhino has a built-in shell, or you can tell it to execute a specific JavaScript file. It interoperates with Java, so if you do this, you have easy access to all essentially of the functionality available to Java.
Where is javascript commonly used beside the web browsers?
I use it for shell scripting on Windows. I also use it as a server-side language, for instance in the server-side part of a web application. It's also used in other environments where a lightweight, powerful scripting language is useful, such as in the MongoDB shell environment (you can use it to query MongoDB data) and stored procedures.
All of that said, writing a browser-based project is a rich, interactive way to learn the language.
windows Sidebar Gadgets, Apple's Widgets, and Google Desktop Gadgets are all created using HTML/ JS/ CSS.
I learnt Javascript by creating a few small Windows Sidebar Gadgets.
Getting Started
Sidebar Reference
You could use javascript to make HTA (HTML Applications) that can be run outside of the the web browser sandbox. MSDN intro to HTA ApplicationsJavascript Tutorial on HTML Applications
You could write a non-blocking TCP server.
Node.js supports that.
Common uses of javascript outside of browsers are WSH scripts and HTA applications on Windows and Dashboard widgets on Mac.
I need to edit an xml file using javascript. Now I'm involved in a project of online testing.
The question.xml file is already in the project folder.
In that i want to add or edit the questions(only using javascript). I'm able to bring the particular content through ajax, but I am not able to edit the file.
Javascript can't write to a file. The best you'll be able to do is get Javascript to read and edit the XML then post that data to a server-side script to write to file.
Until now, Google Chrome is the only web browser that has a functioning implementation of the FileSystem API, therefore, it may allow you to save files locally using only Javascript.
Obviously, for security reasons, when writing files to the local file system, the user must explicitly allow it.
A working tutorial: http://www.html5rocks.com/en/tutorials/file/filesystem/
Nickf is correct. The reason Javascript can't write to a file is because it is a Client-Side language. Javascript will never have permission to write a file because it has to operate inside the browser sandbox.
You will need to use a server-side script (.NET, PHP, ColdFusion, etc) to write the file.
If you are willing to use Google Gears, you get a sandbox on the client machine on which you can write files.
Javascript has no built-in file I/O (a.k.a. you can't do it with JS alone)
Instead use some kind of server side language such as PHP or ASP.NET in conjunction with Javascript's AJAX functionality.
Look over Adobe's Flex development system. There are ways you can use it to build an app that runs in the browser (or not) and can access the filesystem (Windows/Mac/Linux). It's programmed in ActionScript, a dialect of javascript; and can interoperate with javascript in the browser.