| 1 |
"use strict"; |
| 2 |
|
| 3 |
var fs = require("fs") |
| 4 |
, resolve = require("path").resolve |
| 5 |
, rmdir = require("../rmdir") |
| 6 |
, readFile = fs.readFile |
| 7 |
, unlink = fs.unlink |
| 8 |
, pgPath = resolve(__dirname, "./__playground") |
| 9 |
, overwritePath = resolve(pgPath, "write-file-test") |
| 10 |
, intermediateDirPath = resolve(pgPath, "_write-file") |
| 11 |
, intermediatePath = resolve(intermediateDirPath, "intermediate/test"); |
| 12 |
|
| 13 |
module.exports = { |
| 14 |
Overwrite: function (t, a, d) { |
| 15 |
t(overwritePath, "raz", function (err) { a(err, null, "#1"); }); |
| 16 |
t(overwritePath, "dwa", function (err) { a(err, null, "#2"); }); |
| 17 |
t(overwritePath, "trzy", function (err) { |
| 18 |
a(err, null, "#3"); |
| 19 |
readFile(overwritePath, function (err2, content) { |
| 20 |
a(String(content), "trzy", "Last written"); |
| 21 |
unlink(overwritePath, d); |
| 22 |
}); |
| 23 |
}); |
| 24 |
}, |
| 25 |
Intermediate: function (t, a, d) { |
| 26 |
t(intermediatePath, "elo", { intermediate: true }, function (err) { |
| 27 |
if (err) { |
| 28 |
d(err); |
| 29 |
return; |
| 30 |
} |
| 31 |
fs.readFile(intermediatePath, function (err2, content) { |
| 32 |
if (err2) { |
| 33 |
d(err2); |
| 34 |
return; |
| 35 |
} |
| 36 |
a(String(content), "elo", "Content"); |
| 37 |
rmdir(intermediateDirPath, { recursive: true, force: true }, d); |
| 38 |
}); |
| 39 |
}); |
| 40 |
} |
| 41 |
}; |