Permalink
Browse files

Initial commit.

  • Loading branch information...
0 parents commit 2525503f7aa12f91d47de1bbe538794a7410e302 @jprichardson committed Nov 16, 2011
Showing with 169 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +16 −0 LICENSE
  3. +55 −0 README.asciidoc
  4. +11 −0 bin/TEST_file-extra
  5. +7 −0 index.coffee
  6. +18 −0 lib/copy.coffee
  7. +30 −0 package.json
  8. +31 −0 spec/copy.spec.coffee
@@ -0,0 +1 @@
+node_modules/
@@ -0,0 +1,16 @@
+
+(The MIT License)
+
+Copyright (c) 2011 JP Richardson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
+(the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
+ merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
+OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,55 @@
+Node.js: fs-extra
+-------------------
+
+This module simply patches the Node.js 'fs' object with extra methods.
+
+Installation
+~~~~~~~~~~~~
+
+----
+npm install file-extra
+----
+
+Make sure that you run the test script to verify that it works on your system.
+----
+#Mac OS X or Linux Users:
+TEST_fs-extra
+
+#Windows Users:
+coffee TEST_fs-extra
+----
+
+Usage
+~~~~~
+
+----
+fs = require('fs-extra')
+----
+
+You can still use all of the vanilla Node.js path methods. At this time, there is only one extra method.
+
+Methods:
+----
+fs.copyFileSync(srcFile, destFile) //synchronously copies a file
+----
+
+License
+~~~~~~~
+
+(The MIT License)
+
+Copyright (c) 2011 JP Richardson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
+(the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
+ merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
+OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+
@@ -0,0 +1,11 @@
+#!/usr/bin/env coffee
+
+exec = require('child_process').exec
+path = require('path')
+
+process.chdir(path.join(__dirname.replace('bin','')))
+
+exec "jasmine-node --color --coffee spec/", (err, stdout, stderr) ->
+ console.log stdout
+ console.log stderr
+ if err then console.log "ERROR"
@@ -0,0 +1,7 @@
+fs = require('fs')
+
+#fs-extra
+copy = require('./lib/copy')
+fs.copyFileSync = copy.copyFileSync
+
+module.exports = fs
@@ -0,0 +1,18 @@
+fs = require('fs')
+
+BUF_LENGTH = 64*1024
+_buff = new Buffer(BUF_LENGTH)
+
+copyFileSync = (srcFile, destFile) ->
+ fdr = fs.openSync(srcFile, 'r')
+ fdw = fs.openSync(destFile, 'w')
+ bytesRead = 1
+ pos = 0
+ while bytesRead > 0
+ bytesRead = fs.readSync(fdr, _buff, 0, BUF_LENGTH, pos)
+ fs.writeSync(fdw,_buff,0,bytesRead)
+ pos += bytesRead
+ fs.closeSync(fdr)
+ fs.closeSync(fdw)
+
+module.exports.copyFileSync = copyFileSync
@@ -0,0 +1,30 @@
+{
+ "name" : "fs-extra"
+ , "version" : "0.0.1"
+ , "description" : "fs-extra contains methods that aren't included in the vanilla Node.js fs package."
+ , "homepage" :
+ [
+ "https://github.com/jprichardson/node-fs-extra"
+ ]
+ , "repository" : { "type" : "git"
+ , "url" : "https://github.com/jprichardson/node-fs-exra"
+ }
+ , "keywords" : ["fs","file","file system", "copy"]
+ , "author" : "JP Richardson <jprichardson@gmail.com>"
+ , "licenses" : [
+ {
+ "type" : "MIT"
+ ,"url" : "http://github.com/jprichardson/node-fs-extra/raw/master/LICENSE"
+ }
+ ]
+ , "dependencies" : {
+ "coffee-script" : ">=1.0.1"
+ , "jasmine-node": ">=1.0.12"
+ , "path-extra": ">=0.0.1"
+
+ }
+ , "bin" : {
+ "TEST_file-extra": "./bin/TEST_file-extra"
+ }
+ , "main" : "index"
+}
@@ -0,0 +1,31 @@
+crypto = require('crypto')
+fs = require('fs-extra')
+path = require('path-extra')
+
+describe 'fs-extra', ->
+
+ it 'should copy synchronously', ->
+ buf = new Buffer(16*64*1024+7)
+ bytesWritten = 0
+ while bytesWritten < buf.length
+ stringOrNum = (Math.random() <= 0.5)
+ data = Math.random()
+ if stringOrNum
+ buf[bytesWritten] = Math.floor((Math.random()*256))
+ bytesWritten += 1
+ else
+ d = data.toString().replace('0.','')
+ bytesWritten += buf.write(d.substring(0,4), bytesWritten)
+
+ ex = Date.now()
+ fileToWrite = path.join(path.tempdir(), "TEST_fs-extra_write-#{ex}")
+ fileToCopy = path.join(path.tempdir(), "TEST_fs-extra_copy-#{ex}")
+
+ bufMd5 = crypto.createHash('md5').update(buf).digest("hex")
+ fs.writeFileSync(fileToWrite, buf)
+ writeMd5 = crypto.createHash('md5').update(fs.readFileSync(fileToWrite)).digest("hex")
+ fs.copyFileSync(fileToWrite, fileToCopy)
+ copyMd5 = crypto.createHash('md5').update(fs.readFileSync(fileToCopy)).digest("hex")
+
+ expect(bufMd5).toEqual(copyMd5)
+

0 comments on commit 2525503

Please sign in to comment.