Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added file api readme #105

Merged
merged 1 commit into from
Nov 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Start a local, blank cluster. See [Integrate](https://github.com/opentdf/opentdf
### Usage

```typescript
const { AuthProviders, NanoTDFClient } = require('@opentdf/client');

const oidcCredentials: RefreshTokenCredentials = {
clientId: keycloakClientId,
exchange: 'refresh',
Expand All @@ -25,7 +27,27 @@ Start a local, blank cluster. See [Integrate](https://github.com/opentdf/opentdf
const cipherText = await client.encrypt(plainText);
const clearText = await client.decrypt(cipherText);
```
For files:
```typescript
const { FileClient } = require('@opentdf/client');

// for file Encryption
const fileClient = new FileClient(
{ ...oidcCredentials, kasEndpoint }, ['userWeGrantAccessTo']
);

const cipherStream = await fileClient.encrypt('originalFile.jpeg');
await cipherStream.toFile('encryptedFile.tdf');

const fromReadStream = await fileClient.decrypt(fs.createReadStream('encryptedFile.tdf'));
await fromReadStream.toFile('decryptedFile.jpeg')
```

FileClient encrypt/decrypt supports [Webstream](https://streams.spec.whatwg.org/#rs-model),
[Node stream](https://nodejs.org/api/stream.html#readable-streams),
[Buffer](https://nodejs.org/dist/latest-v18.x/docs/api/buffer.html),
[Array Buffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer),
String (as path to file).
### Examples

Review examples to see how to integrate. See [Examples](https://github.com/opentdf/opentdf/tree/main/examples)
Expand Down