Skip to content

Commit da857b2

Browse files
committed
0.1.5
1 parent 3362016 commit da857b2

File tree

13 files changed

+133
-12
lines changed

13 files changed

+133
-12
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,5 @@ Cargo.lock
196196

197197
*.node
198198
*.exe
199+
200+
@refclone

README.md

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# @refclone/refclone
2+
3+
[![npm version](https://badge.fury.io/js/%40refclone%2Frefclone.svg)](https://www.npmjs.com/package/@refclone/refclone)
4+
[![Build Status](https://github.com/nachoaldamav/cross-reflink/workflows/CI/badge.svg)](https://github.com/nachoaldamav/cross-reflink/actions)
5+
6+
Copy-on-write file cloning for Node.js, powered by the NAPI-RS and built upon [reflink-copy](https://github.com/cargo-bins/reflink-copy). This package supports a variety of platforms, including ARM and x86 architectures.
7+
8+
### Supported Platforms
9+
- Linux
10+
- MacOS
11+
- Windows (Server 2012+ and Windows Dev Drives)
12+
13+
## Installation
14+
15+
Just install `@refclone/refclone` using your favorite package manager:
16+
17+
```bash
18+
pnpm add @refclone/refclone
19+
```
20+
21+
## Usage
22+
23+
The package provides both synchronous and asynchronous methods to clone files.
24+
25+
### TypeScript Usage
26+
27+
First, import the package:
28+
29+
```typescript
30+
import { reflinkFileSync, reflinkFile } from '@refclone/refclone';
31+
```
32+
33+
#### Synchronous Method
34+
35+
```typescript
36+
reflinkFileSync('source.txt', 'destination.txt');
37+
```
38+
39+
#### Asynchronous Method
40+
41+
```typescript
42+
await reflinkFile('source.txt', 'destination.txt');
43+
```
44+
45+
## Testing
46+
47+
This package is tested using `vitest`. You can run the tests locally using:
48+
49+
```bash
50+
yarn install
51+
yarn build
52+
yarn test
53+
```

__test__/main.spec.ts

+45-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
afterAll,
3-
afterEach,
43
beforeAll,
54
beforeEach,
65
describe,
@@ -9,7 +8,7 @@ import {
98
} from 'vitest';
109
import { join } from 'path';
1110
import { reflinkFileSync, reflinkFile } from '../index.js';
12-
import { mkdir, readFile, rm, writeFile } from 'fs/promises';
11+
import { mkdir, rm, writeFile } from 'fs/promises';
1312
import { readFileSync } from 'fs';
1413
import { randomUUID } from 'crypto';
1514

@@ -150,6 +149,50 @@ describe('reflink', () => {
150149
}).toThrow();
151150
});
152151

152+
it('should not fail with relative paths', async () => {
153+
const file = {
154+
path: "file.txt",
155+
content: "Hello World!",
156+
}
157+
158+
const dest = "file-copy.txt";
159+
160+
await rm(dest, { force: true });
161+
await writeFile(file.path, file.content);
162+
163+
await reflinkFile(file.path, dest);
164+
165+
const content = readFileSync(dest, 'utf-8');
166+
167+
expect(content).toBe(file.content);
168+
169+
// clean both files
170+
await rm("file.txt");
171+
await rm("file-copy.txt");
172+
});
173+
174+
it('should not fail with nested relative paths', async () => {
175+
const file = {
176+
path: "nested/file.txt",
177+
content: "Hello World!",
178+
}
179+
180+
const dest = "nested/file-copy.txt";
181+
182+
await rm(dest, { force: true });
183+
await mkdir("nested", { recursive: true });
184+
await writeFile(file.path, file.content);
185+
186+
await reflinkFile(file.path, dest);
187+
188+
const content = readFileSync(dest, 'utf-8');
189+
190+
expect(content).toBe(file.content);
191+
192+
// clean both files
193+
await rm("nested", { recursive: true });
194+
});
195+
153196
it('should correctly clone 1000 files (sync)', async () => {
154197
const files = Array.from({ length: 1000 }, (_, i) => ({
155198
path: join(sandboxDir, `file${i}.txt`),

file.txt

-1
This file was deleted.

npm/darwin-arm64/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
"os": [
1010
"darwin"
1111
],
12+
"cpu": [
13+
"arm64"
14+
],
1215
"main": "refclone.darwin-arm64.node",
1316
"files": [
1417
"refclone.darwin-arm64.node"
@@ -17,4 +20,4 @@
1720
"engines": {
1821
"node": ">= 10"
1922
}
20-
}
23+
}

npm/darwin-x64/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
"os": [
1010
"darwin"
1111
],
12+
"cpu": [
13+
"x64"
14+
],
1215
"main": "refclone.darwin-x64.node",
1316
"files": [
1417
"refclone.darwin-x64.node"
@@ -17,4 +20,4 @@
1720
"engines": {
1821
"node": ">= 10"
1922
}
20-
}
23+
}

npm/linux-arm64-gnu/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
"os": [
1010
"linux"
1111
],
12+
"cpu": [
13+
"arm64"
14+
],
1215
"main": "refclone.linux-arm64-gnu.node",
1316
"files": [
1417
"refclone.linux-arm64-gnu.node"
@@ -20,4 +23,4 @@
2023
"libc": [
2124
"glibc"
2225
]
23-
}
26+
}

npm/linux-arm64-musl/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
"os": [
1010
"linux"
1111
],
12+
"cpu": [
13+
"arm64"
14+
],
1215
"main": "refclone.linux-arm64-musl.node",
1316
"files": [
1417
"refclone.linux-arm64-musl.node"
@@ -20,4 +23,4 @@
2023
"libc": [
2124
"musl"
2225
]
23-
}
26+
}

npm/linux-x64-gnu/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
"os": [
1010
"linux"
1111
],
12+
"cpu": [
13+
"x64"
14+
],
1215
"main": "refclone.linux-x64-gnu.node",
1316
"files": [
1417
"refclone.linux-x64-gnu.node"
@@ -20,4 +23,4 @@
2023
"libc": [
2124
"glibc"
2225
]
23-
}
26+
}

npm/linux-x64-musl/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
"os": [
1010
"linux"
1111
],
12+
"cpu": [
13+
"x64"
14+
],
1215
"main": "refclone.linux-x64-musl.node",
1316
"files": [
1417
"refclone.linux-x64-musl.node"
@@ -20,4 +23,4 @@
2023
"libc": [
2124
"musl"
2225
]
23-
}
26+
}

npm/win32-arm64-msvc/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
"os": [
1010
"win32"
1111
],
12+
"cpu": [
13+
"arm64"
14+
],
1215
"main": "refclone.win32-arm64-msvc.node",
1316
"files": [
1417
"refclone.win32-arm64-msvc.node"
@@ -17,4 +20,4 @@
1720
"engines": {
1821
"node": ">= 10"
1922
}
20-
}
23+
}

npm/win32-x64-msvc/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
"os": [
1010
"win32"
1111
],
12+
"cpu": [
13+
"x64"
14+
],
1215
"main": "refclone.win32-x64-msvc.node",
1316
"files": [
1417
"refclone.win32-x64-msvc.node"
@@ -17,4 +20,4 @@
1720
"engines": {
1821
"node": ">= 10"
1922
}
20-
}
23+
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@refclone/refclone",
3-
"version": "0.1.4",
3+
"version": "0.1.5",
44
"main": "index.js",
55
"types": "index.d.ts",
66
"repository": {

0 commit comments

Comments
 (0)