mirror of
https://github.com/jprichardson/node-fs-extra.git
synced 2026-01-25 16:42:57 +00:00
Implemented and tested rmrf.
This commit is contained in:
parent
e7b61c5dae
commit
ec64f4397e
@ -5,4 +5,8 @@ copy = require('./lib/copy')
|
||||
fs.copyFileSync = copy.copyFileSync
|
||||
fs.copyFile = copy.copyFile
|
||||
|
||||
remove = require('./lib/remove')
|
||||
fs.rmrfSync = remove.rmrfSync
|
||||
fs.rmrf = remove.rmrf
|
||||
|
||||
module.exports = fs
|
||||
10
lib/remove.coffee
Normal file
10
lib/remove.coffee
Normal file
@ -0,0 +1,10 @@
|
||||
rimraf = require('rimraf')
|
||||
|
||||
rmrfSync = (dir) ->
|
||||
rimraf.sync(dir)
|
||||
|
||||
rmrf = (dir,cb) ->
|
||||
rimraf(dir,cb)
|
||||
|
||||
module.exports.rmrfSync = rmrfSync
|
||||
module.exports.rmrf = rmrf
|
||||
@ -20,7 +20,7 @@ buildBuffer = (size) ->
|
||||
bytesWritten += buf.write(d.substring(0,4), bytesWritten)
|
||||
buf
|
||||
|
||||
describe 'fs-extra', ->
|
||||
describe 'fs-extra: copy', ->
|
||||
|
||||
describe 'copyFileSync', ->
|
||||
it 'should copy synchronously', ->
|
||||
@ -40,7 +40,7 @@ describe 'fs-extra', ->
|
||||
|
||||
|
||||
describe 'copyFile', ->
|
||||
it 'should copy asynchronously', ->
|
||||
it 'should copy asynchronously', (done) ->
|
||||
buf = buildBuffer(16*64*1024+7)
|
||||
ex = Date.now()
|
||||
fileSrc = path.join(path.tempdir(), "TEST_fs-extra_write-#{ex}")
|
||||
@ -52,13 +52,14 @@ describe 'fs-extra', ->
|
||||
|
||||
destMd5 = ''
|
||||
|
||||
runs ->
|
||||
fs.copyFile fileSrc, fileDest, (err) ->
|
||||
destMd5 = crypto.createHash('md5').update(fs.readFileSync(fileDest)).digest("hex")
|
||||
waitsFor -> destMd5 isnt ''
|
||||
runs ->
|
||||
fs.copyFile fileSrc, fileDest, (err) ->
|
||||
destMd5 = crypto.createHash('md5').update(fs.readFileSync(fileDest)).digest("hex")
|
||||
T bufMd5 is destMd5
|
||||
T srcMd5 is destMd5
|
||||
done()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
3
test/mocha.opts
Normal file
3
test/mocha.opts
Normal file
@ -0,0 +1,3 @@
|
||||
--reporter spec
|
||||
--ui bdd
|
||||
--growl
|
||||
48
test/remove.test.coffee
Normal file
48
test/remove.test.coffee
Normal file
@ -0,0 +1,48 @@
|
||||
crypto = require('crypto')
|
||||
fs = require('fs-extra')
|
||||
path = require('path-extra')
|
||||
assert = require('assert')
|
||||
|
||||
T = (v) -> assert(v)
|
||||
F = (v) -> assert(!v)
|
||||
|
||||
buildDir = ->
|
||||
buf = new Buffer(5) #small buffer for data
|
||||
bytesWritten = 0
|
||||
while bytesWritten < buf.length
|
||||
buf[bytesWritten] = Math.floor((Math.random()*256))
|
||||
bytesWritten += 1
|
||||
|
||||
ex = Date.now()
|
||||
baseDir = path.join(path.tempdir(), "TEST_fs-extra_rmrf-#{ex}")
|
||||
fs.mkdirSync(baseDir)
|
||||
|
||||
fs.writeFileSync(path.join(baseDir, Math.random() + ''), buf)
|
||||
fs.writeFileSync(path.join(baseDir, Math.random() + ''), buf)
|
||||
|
||||
subDir = path.join(path.tempdir(), Math.random() + '')
|
||||
fs.mkdirSync(subDir)
|
||||
|
||||
fs.writeFileSync(path.join(subDir, Math.random() + ''))
|
||||
baseDir
|
||||
|
||||
describe 'fs-extra: remove', ->
|
||||
|
||||
describe 'rmrfSync', ->
|
||||
it 'should remove directories and files synchronously', ->
|
||||
dir = buildDir()
|
||||
T path.existsSync(dir)
|
||||
fs.rmrfSync(dir)
|
||||
F path.existsSync(dir)
|
||||
|
||||
|
||||
describe 'rmrf', ->
|
||||
it 'should remove directories and files asynchronously', (done) ->
|
||||
dir = buildDir()
|
||||
T path.existsSync(dir)
|
||||
fs.rmrf dir, ->
|
||||
F path.existsSync(dir)
|
||||
done()
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user