Skip to content

Commit

Permalink
0.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
nachoaldamav committed Oct 2, 2023
1 parent 3362016 commit da857b2
Show file tree
Hide file tree
Showing 13 changed files with 133 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,5 @@ Cargo.lock

*.node
*.exe

@refclone
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# @refclone/refclone

[![npm version](https://badge.fury.io/js/%40refclone%2Frefclone.svg)](https://www.npmjs.com/package/@refclone/refclone)
[![Build Status](https://github.com/nachoaldamav/cross-reflink/workflows/CI/badge.svg)](https://github.com/nachoaldamav/cross-reflink/actions)

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.

### Supported Platforms
- Linux
- MacOS
- Windows (Server 2012+ and Windows Dev Drives)

## Installation

Just install `@refclone/refclone` using your favorite package manager:

```bash
pnpm add @refclone/refclone
```

## Usage

The package provides both synchronous and asynchronous methods to clone files.

### TypeScript Usage

First, import the package:

```typescript
import { reflinkFileSync, reflinkFile } from '@refclone/refclone';
```

#### Synchronous Method

```typescript
reflinkFileSync('source.txt', 'destination.txt');
```

#### Asynchronous Method

```typescript
await reflinkFile('source.txt', 'destination.txt');
```

## Testing

This package is tested using `vitest`. You can run the tests locally using:

```bash
yarn install
yarn build
yarn test
```
47 changes: 45 additions & 2 deletions __test__/main.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
afterAll,
afterEach,
beforeAll,
beforeEach,
describe,
Expand All @@ -9,7 +8,7 @@ import {
} from 'vitest';
import { join } from 'path';
import { reflinkFileSync, reflinkFile } from '../index.js';
import { mkdir, readFile, rm, writeFile } from 'fs/promises';
import { mkdir, rm, writeFile } from 'fs/promises';
import { readFileSync } from 'fs';
import { randomUUID } from 'crypto';

Expand Down Expand Up @@ -150,6 +149,50 @@ describe('reflink', () => {
}).toThrow();
});

it('should not fail with relative paths', async () => {
const file = {
path: "file.txt",
content: "Hello World!",
}

const dest = "file-copy.txt";

await rm(dest, { force: true });
await writeFile(file.path, file.content);

await reflinkFile(file.path, dest);

const content = readFileSync(dest, 'utf-8');

expect(content).toBe(file.content);

// clean both files
await rm("file.txt");
await rm("file-copy.txt");
});

it('should not fail with nested relative paths', async () => {
const file = {
path: "nested/file.txt",
content: "Hello World!",
}

const dest = "nested/file-copy.txt";

await rm(dest, { force: true });
await mkdir("nested", { recursive: true });
await writeFile(file.path, file.content);

await reflinkFile(file.path, dest);

const content = readFileSync(dest, 'utf-8');

expect(content).toBe(file.content);

// clean both files
await rm("nested", { recursive: true });
});

it('should correctly clone 1000 files (sync)', async () => {
const files = Array.from({ length: 1000 }, (_, i) => ({
path: join(sandboxDir, `file${i}.txt`),
Expand Down
1 change: 0 additions & 1 deletion file.txt

This file was deleted.

5 changes: 4 additions & 1 deletion npm/darwin-arm64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"os": [
"darwin"
],
"cpu": [
"arm64"
],
"main": "refclone.darwin-arm64.node",
"files": [
"refclone.darwin-arm64.node"
Expand All @@ -17,4 +20,4 @@
"engines": {
"node": ">= 10"
}
}
}
5 changes: 4 additions & 1 deletion npm/darwin-x64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"os": [
"darwin"
],
"cpu": [
"x64"
],
"main": "refclone.darwin-x64.node",
"files": [
"refclone.darwin-x64.node"
Expand All @@ -17,4 +20,4 @@
"engines": {
"node": ">= 10"
}
}
}
5 changes: 4 additions & 1 deletion npm/linux-arm64-gnu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"os": [
"linux"
],
"cpu": [
"arm64"
],
"main": "refclone.linux-arm64-gnu.node",
"files": [
"refclone.linux-arm64-gnu.node"
Expand All @@ -20,4 +23,4 @@
"libc": [
"glibc"
]
}
}
5 changes: 4 additions & 1 deletion npm/linux-arm64-musl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"os": [
"linux"
],
"cpu": [
"arm64"
],
"main": "refclone.linux-arm64-musl.node",
"files": [
"refclone.linux-arm64-musl.node"
Expand All @@ -20,4 +23,4 @@
"libc": [
"musl"
]
}
}
5 changes: 4 additions & 1 deletion npm/linux-x64-gnu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"os": [
"linux"
],
"cpu": [
"x64"
],
"main": "refclone.linux-x64-gnu.node",
"files": [
"refclone.linux-x64-gnu.node"
Expand All @@ -20,4 +23,4 @@
"libc": [
"glibc"
]
}
}
5 changes: 4 additions & 1 deletion npm/linux-x64-musl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"os": [
"linux"
],
"cpu": [
"x64"
],
"main": "refclone.linux-x64-musl.node",
"files": [
"refclone.linux-x64-musl.node"
Expand All @@ -20,4 +23,4 @@
"libc": [
"musl"
]
}
}
5 changes: 4 additions & 1 deletion npm/win32-arm64-msvc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"os": [
"win32"
],
"cpu": [
"arm64"
],
"main": "refclone.win32-arm64-msvc.node",
"files": [
"refclone.win32-arm64-msvc.node"
Expand All @@ -17,4 +20,4 @@
"engines": {
"node": ">= 10"
}
}
}
5 changes: 4 additions & 1 deletion npm/win32-x64-msvc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"os": [
"win32"
],
"cpu": [
"x64"
],
"main": "refclone.win32-x64-msvc.node",
"files": [
"refclone.win32-x64-msvc.node"
Expand All @@ -17,4 +20,4 @@
"engines": {
"node": ">= 10"
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@refclone/refclone",
"version": "0.1.4",
"version": "0.1.5",
"main": "index.js",
"types": "index.d.ts",
"repository": {
Expand Down

0 comments on commit da857b2

Please sign in to comment.