Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@autonomys/auto-dag-data

Package Overview
Dependencies
Maintainers
0
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@autonomys/auto-dag-data

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
361
increased by56.28%
Maintainers
0
Weekly downloads
 
Created
Source

Auto DAG Data

Autonomys Banner

Latest Github release Build status of the main branch on Linux/OSX npm version

Overview

The Autonomys Auto DAG Data SDK (@autonomys/auto-dag-data) provides utilities for creating and managing IPLD DAGs (InterPlanetary Linked Data Directed Acyclic Graphs) for files and folders. It facilitates chunking large files, handling metadata, and creating folder structures suitable for distributed storage systems like IPFS.

Features

  • File Chunking and DAG Creation: Efficiently split large files into smaller chunks and create IPLD DAGs.
  • Folder Structure Creation: Generate IPLD DAGs for directory structures.
  • Metadata Handling: Add and manage metadata for files and folders.
  • CID Management: Utilities for working with Content Identifiers (CIDs).
  • TypeScript Support: Fully typed for enhanced developer experience.

Installation

You can install Auto-DAG-Data using npm or yarn:

npm install @autonomys/auto-dag-data

or

yarn add @autonomys/auto-dag-data

Usage

Creating an IPLD DAG from a File

To create an IPLD DAG from a file, you can use the createFileIPLDDag function:

import { createFileIPLDDag } from '@autonomys/auto-dag-data'
import fs from 'fs'

const fileBuffer = fs.readFileSync('path/to/your/file.txt')

const dag = createFileIPLDDag(fileBuffer, 'file.txt')

Creating an IPLD DAG from a Folder

To create an IPLD DAG from a folder, you can use the createFolderIPLDDag function:

import { createFolderIPLDDag } from '@autonomys/auto-dag-data'
import { CID } from 'multiformats'

// Example child CIDs and folder information
const childCIDs: CID[] = [
  /* array of CIDs */
]
const folderName = 'my-folder'
const folderSize = 1024 // size in bytes

const folderDag = createFolderIPLDDag(childCIDs, folderName, folderSize)

Working with CIDs

You can use functions from the cid module to work with CIDs:

import { cidOfNode, cidToString, stringToCid } from '@autonomys/auto-dag-data'

// Create a CID from a node
const cid = cidOfNode(dag.head)

// Convert the CID to a string
const cidString = cidToString(cid)

// Parse a string back into a CID
const parsedCID = stringToCid(cidString)

Encoding and Decoding Nodes

You can encode and decode IPLD nodes:

import { encodeNode, decodeNode } from '@autonomys/auto-dag-data'

// Encode a node
const encodedNode = encodeNode(dag.head)

// Decode a node
const decodedNode = decodeNode(encodedNode)

Handling Metadata

To add metadata to a node, you can create a metadata node:

import { createMetadataNode } from '@autonomys/auto-dag-data'

const metadata = {
  name: 'My File',
  description: 'This is a sample file',
  // ... other metadata fields
}

const metadataNode = createMetadataNode(metadata)

Example: Creating a File DAG and Converting to CID

import { createFileIPLDDag, cidOfNode, cidToString } from '@autonomys/auto-dag-data'
import fs from 'fs'

const fileBuffer = fs.readFileSync('path/to/your/file.txt')

const dag = createFileIPLDDag(fileBuffer, 'file.txt')

const cid = cidOfNode(dag.headCID)
const cidString = cidToString(cid)

console.log(`CID of the file DAG: ${cidString}`)

Example: Converting Metadata To DAG

import {
  createMetadataIPLDDag,
  cidOfNode,
  cidToString,
  type OffchainMetadata,
} from '@autonomys/auto-dag-data'
import fs from 'fs'

const metadata: OffchainMetadata = fs.readFileSync('path/to/your/metadata.json')

const dag = createMetadataIPLDDag(metadata)

const cid = cidOfNode(dag.headCID)
const cidString = cidToString(cid)

console.log(`CID of the metadata DAG: ${cidString}`)

License

This project is licensed under the MIT License. See the LICENSE file for details.

Additional Resources

Contact

If you have any questions or need support, feel free to reach out:

We appreciate your feedback and contributions!

FAQs

Package last updated on 07 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc