Download dotfile using html5 download preserving name - html

I have a directory structure, containing a list of directories and files.
I want to give user an option of downloading a file. For downloading, I'm using HTML5 download attribute. It works perfectly.
But the directory structure i have can have dotfiles too, examples: .babelrc, .gitignore, .eslintrc, etc.
When I use the same technique to download such files, file is being downloaded with the same content but the file is no longer a dotfile. After downloading, let's say .gitignore, the file becomes gitignore.txt.
I'm using this for my project github-plus - Chrome extension to display size of each file, download link and an option of copying it's contents.
Any help would be highly appreciated.
I'm using this format:
Download
JSFIDDLE DEMO

Quoting HTML5 specification on downloading resources with the download attribute, about file type/extension :
If the claimed type is known, then alter filename to add an extension corresponding to claimed type.
Otherwise, if named type is known to be potentially dangerous (e.g. it will be treated by the platform conventions as a native executable, shell script, HTML application, or executable-macro-capable document) then optionally alter filename to add a known-safe extension (e.g. ".txt").
It seems that:
the part of the algorithm that finally choses the filename is platform-dependent
if the extension is not recognised, as in the case of dotfiles, the browser will try to determine it by using the file MIME type
dotfiles might be considered anyway as potentially harmful as they are hidden files on various platforms. This seems to be what happens in your case, with the initial dot being removed and the .txt extension appended.

Related

MIME-type of files queries

I'm doing a computing assignment, and I read this passage and had no clue. I don't get the full picture behind what MIME-type are...
"Note that filelename extensions are not the same as file types. Some filesles may end in .html or .htm but
the header indicates that the MIME-type is text/plain. On the other hand, a file may have an extension
.txt - or no extension - but have a MIME-type of text/html. The MIME-type defines the true type
of the file."
What do you mean by the MIME-type defines the true type of file?
Thank you so much!
I can give a self-learning experience
in windows open Registry Editor
Start -> Run -> regedit
Expand HKEY_CLASSES_ROOT
choose any extension you want say (.pdf)
you can understand how is it related and how it is treated
Again expand .pdf, you can see through which application it is usually processed
this makes a perfect learning experience of various MIME types and its content type and which application it is as default processed
MIME type is not only determined by the ending of a file, it also refers to the content in the file i.e. a python script s.py has MIME type text/x-python, while an empty file named s.py has inode/x-empty on a linux system
In linux use file --mime-type FILE_NAME command
How can I find out a file's MIME type (Content-Type)?
MIME types are just a way to identify the type of a file. Typically, there are two ways to figure out what the type of a file is:
Look at the file extension. For example, a pdf is usually saved as file.pdf ending with the extension pdf. This is a hint that the type of the file is pdf file. However, you can change the name of the file and simply change its extension to something else. So, the name of a file does not necessarily have to indicate its type
Look at the contents of the file and try to guess based on how its arranged in binary.
Most binary files have very specific representation inside a file. For example, if you open a pdf file in a notepad (or any text editing program), you will find that it starts with %PDF-. Followed by some numbers and potentially weird characters. This tells you that this is a pdf type.
Why is this useful? Files are simply saved as blocks of binary data. However, certain files can only be opened by certain programs (for example, music files can't be "opened" by text editors, it can only be played with a music player). By figuring out the MIME type of a file, you can understand how to interpret the data in the file (for example, text, image, video, audio are common mime types). Then, you can use the correct software to use the file.

Why do we use file extensions if the content is just plain text?

From what I can see, a browser will display the information found both in .txt files or .html files, properly displaying html tags inside them. My g++ compiler won't stop segnaling errors in a .lua file containing lua code, but it will still try compiling it without caring about the extension, while the lua interpreter won't even open a .cpp file, even if I wrote a perfectly working lua program inside.
So why do we need file extensions if the content is in all cases text? As I said, I could write a C++ program in a file with an arbitrary extension and it will properly compile it, so what are extensions even for?
On many systems you can associate extensions with certain applications. For example a double click on a .cpp file will open it in a C++ IDE while a double click on a .txt file will open it in the default text editor.
Another example: Most text editors have syntax highlighting that depends on the extension.
There are probably many more cases where the extension is useful as an indicator for the file type. Of course this is nothing but a convention, but one that has been established for decades.

Inject/Remove HTML via Chrome Extension

I'm making a chrome extension and on a specific web page I have a table that has commented out information.
I'd like to remove the comment syntax so that the information is displayed in the table
What kind of content script would I need to parse the HTML for the specific comment syntax and then remove it?
Also, every time I pack my extension to a .crx file the file size nearly doubles. Is this standard? My 16 kb files are turning into a 40 MB extension- I'm worried that it isn't supposed to work like that.
First off, likely when you package your extension into a .crx file, you're putting the resulting .crx file in the same folder as your source files.
Then the next time that you package the extension, instead of your source folder having just the files you want to package, it has the files you want to package plus the previous .crx file. Every time this happens you effectively (just over) double the file size. To prevent this, make sure the .crx file is getting saved to the parent directory.
As far as the uncommenting HTML goes, I would check out this answer:
Uncomment html code using javascript

Provide a description for a file dialog

In HTML5, I can get an open file dialog with the following code:
<input id="fileOpenDialog" type="file" accept=".proj" />
(note, .abc is my own project format)
When Google Chrome opens the dialog, it shows it like this:
Is there a way to provide an additional description for the file type? I would like it to show something like "ABC Project File (.proj)".
Although I like the suggestion, there is no attribute in the input type=file that supports this.
File extensions are kept on the client, and those values are shown in the dropdown.
You can find all supported attributes in the specification.
No this isn't possible.
That said, however, your upload form itself should clearly specify which type of file is being requested from the user; the user should know what file they are expected to load before selecting to chose a file.
Whilst on this subject, it's also worth noting that the HTML5 Candidate Recommendation specifies the following warning:
Warning: Extensions tend to be ambiguous (e.g. there are an untold number of formats that use the ".dat" extension, and users can typically quite easily rename their files to have a ".doc" extension even if they are not Microsoft Word documents), and MIME types tend to be unreliable (e.g. many formats have no formally registered types, and many formats are in practice labeled using a number of different MIME types). Authors are reminded that, as usual, data received from a client should be treated with caution, as it may not be in an expected format even if the user is not hostile and the user agent fully obeyed the accept attribute's requirements.
Even if you were somehow able to rename your desired file type to "ABC Project File (.proj)", the user would still be able to upload any other file with the .proj extension.

Is it possible **to change an .sql file extension to like .myname** and still the software like wamp or sqlite can still read it?

Is it possible to change an .sql file extension to like .myname and still the software like wamp or sqlite can still read it??
-I was just thinking of the possibilities that changing the file extension to something custom could add to db security.
Using sqlite3 in Python you can select any arbitrary file extension (as long as [a-zA-Z]{1,...}) without hindering the module in accessing the database-file.
Note, however, that changing a default file-extension to a different arbitrary one does not increase (or decrease for that matter) security of the data stored in the database in any way.
You'd have to test if other (SQLite-)implementations allow custom extensions as well, but either way, it would have not impact whatsoever on security.
So long as the software in question does not limit itself to only recognizing files ending ".sql", it makes no difference whatsoever.
A file extension is just a label - they do not affect the actual physical contents of a file in any way, and an SQL file is just a text file. That .sql extension is really more of a user aid than a software aid - whilst software will use it as a filter (such as only showing .doc files by default on Word's Open dialog), if you tell a program to treat file X as a file of format Y then it will attempt to read it as a Y-formatted file, regardless of extension.
You could change it to .txt and (under Windows) it would open in Notepad instead when double-clicked, or .doc and it would open in Word (probably incorrectly, as Word would attempt to parse it as a Word-formatted file, not a plain text file). The actual contents of the file are completely unaffected.
You could change the .sql to .txt or .doc or .bmp or .wahoo or anything (or even remove the extension entirely), it will still be readable by WAMP etc.
It will have absolutely zero effect on security.