import { resolve } from 'path';
import * as fs from 'fs';
const copy = (source, target, callback) => {
const SIZE = 3;
const buffer = Buffer.alloc(SIZE);
let readOffset = 0;
let writeOffset = 0;
fs.open(source, 'r', (err, rfd) => {
if (err) return callback(err);
fs.open(target, 'w', (err, wfd) => {
if (err) return callback(err);
const next = () => {
fs.read(rfd, buffer, 0, SIZE, readOffset, (err, byteRead) => {
if (err) return callback(err);
fs.write(wfd, buffer, 0, byteRead, writeOffset, (err, written) => {
if (err) return callback(err);
readOffset += byteRead;
writeOffset += written;
if (byteRead < SIZE) {
fs.close(rfd, () => {});
fs.close(wfd, () => {});
callback();
return;
}
next();
});
});
};
next();
});
});
};