Permalink
Browse files

fix file.copy, change README.md

  • Loading branch information...
1 parent 441ef1f commit e96c953fd7e85bc1e13dc321bcb8388b26200e17 @zmmbreeze committed Jan 13, 2013
Showing with 43 additions and 3 deletions.
  1. +1 −0 README.md
  2. +18 −0 lib/file.coffee
  3. +24 −3 lib/file.js
View
@@ -6,6 +6,7 @@ How to install
2. `npm install -g blogin`
3. `blogin init blogdir`
4. `cd blogdir`
+5. Change blog config at "blogdir/blogin.json"
4. `blogin update`
5. `blogin server`
6. Open `http://127.0.0.1:3000` in browser.
View
@@ -57,11 +57,14 @@ exports.writeIfNotExist = (src, content) ->
return true
else
return false
+
###
src: '/home/user/a'
dest: '/home/user/b'
force: true
###
+BUF_LENGTH = 64 * 1024
+_buff = new Buffer(BUF_LENGTH)
copy = exports.copy = (src, dest, force) ->
destExist = fs.existsSync(dest)
if not force and destExist
@@ -75,7 +78,22 @@ copy = exports.copy = (src, dest, force) ->
fs.readdirSync(src).forEach (filename, i) =>
copy(path.resolve(src, filename), path.resolve(dest, filename), force)
else
+ ###
+ if force and destExist
+ console.log(dest)
+ fs.unlinkSync(dest) # remove dest file
fs.createReadStream(src).pipe(fs.createWriteStream(dest))
+ ###
+ fdr = fs.openSync(src, 'r')
+ fdw = fs.openSync(dest, '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)
return true
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit e96c953

Please sign in to comment.