Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix file.copy, change README.md

  • Loading branch information...
commit e96c953fd7e85bc1e13dc321bcb8388b26200e17 1 parent 441ef1f
@zmmbreeze authored
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
1  README.md
@@ -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
18 lib/file.coffee
@@ -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
27 lib/file.js
@@ -1,6 +1,6 @@
// Generated by CoffeeScript 1.4.0
(function() {
- var copy, dir, fs, getFileName, marked, mkdir, moment, path, read, readJSON, write;
+ var BUF_LENGTH, copy, dir, fs, getFileName, marked, mkdir, moment, path, read, readJSON, write, _buff;
fs = require('fs');
@@ -88,8 +88,12 @@
*/
+ BUF_LENGTH = 64 * 1024;
+
+ _buff = new Buffer(BUF_LENGTH);
+
copy = exports.copy = function(src, dest, force) {
- var destExist,
+ var bytesRead, destExist, fdr, fdw, pos,
_this = this;
destExist = fs.existsSync(dest);
if (!force && destExist) {
@@ -103,7 +107,24 @@
return copy(path.resolve(src, filename), path.resolve(dest, filename), force);
});
} else {
- fs.createReadStream(src).pipe(fs.createWriteStream(dest));
+ /*
+ 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;
};
Please sign in to comment.
Something went wrong with that request. Please try again.