JavaScript sha1_file
Calculate the sha1 hash of given filename
1 2 3 4 56 7 8 9 1011 12 13 | function sha1_file (str_filename) { // Calculate the sha1 hash of given filename // // version: 1109.2015 // discuss at: http://phpjs.org/functions/sha1_file // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // - depends on: file_get_contents // - depends on: sha1 // * example 1: sha1_file('http://kevin.vanzonneveld.net/pj_test_supportfile_1.htm'); // * returns 1: '40bd001563085fc35165329ea1ff5c5ecbdbbeef' var buf = this.file_get_contents(str_filename); return this.sha1(buf); } |
Examples
Running
1 | sha1_file('http://kevin.vanzonneveld.net/pj_test_supportfile_1.htm'); |
Should return
1 | '40bd001563085fc35165329ea1ff5c5ecbdbbeef' |
Dependencies
In order to use this function, you also need:
Open syntax issues
php.js uses JsLint to help us keep our code consistent and prevent some common bugs.
Eventually we want all code to pass or at least take into consideration most fixes suggested by JsLint, following this JsLint configuration we’ve decided on.
Authors
Thanks to the following developers, you get to have sha1_file goodness in JavaScript.

Hi!
Kevin van Zonneveld
8 Feb '08
Fixed by putting the regexes between quotes.