{"name":"ipfs-unixfs","version":"1.0.3-rc.3","description":"JavaScript implementation of IPFS' unixfs (a Unix FileSystem representation on top of a MerkleDAG)","leadMaintainer":"Alex Potsides <alex.potsides@protocol.ai>","main":"src/index.js","browser":{"fs":false},"scripts":{"test":"aegir test -t node -t browser -t webworker","test:node":"aegir test -t node","test:browser":"aegir test -t browser","test:webworker":"aegir test -t webworker","build":"aegir build","clean":"rm -rf ./dist","lint":"aegir lint","coverage":"nyc -s aegir test -t node && nyc report --reporter=html","depcheck":"aegir dep-check"},"repository":{"type":"git","url":"git+https://github.com/ipfs/js-ipfs-unixfs.git"},"keywords":["IPFS"],"license":"MIT","bugs":{"url":"https://github.com/ipfs/js-ipfs-unixfs/issues"},"engines":{"node":">=10.0.0","npm":">=4.0.0"},"homepage":"https://github.com/ipfs/js-ipfs-unixfs#readme","devDependencies":{"aegir":"^25.0.0","chai":"^4.2.0","dirty-chai":"^2.0.1","nyc":"^15.0.0"},"dependencies":{"err-code":"^2.0.0","protons":"^1.2.0"},"gitHead":"db60a4232e600e73227e6ab8964be083eada389a","readme":"# ipfs-unixfs JavaScript Implementation <!-- omit in toc -->\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)\n[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)\n[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)\n[![Build Status](https://flat.badgen.net/travis/ipfs/js-ipfs-unixfs)](https://travis-ci.com/ipfs/js-ipfs-unixfs)\n[![Codecov](https://codecov.io/gh/ipfs/js-ipfs-unixfs/branch/master/graph/badge.svg)](https://codecov.io/gh/ipfs/js-ipfs-unixfs)\n\n> JavaScript implementation of IPFS' UnixFS (a Unix FileSystem files representation on top of a MerkleDAG)\n\nThe UnixFS spec can be found inside the [ipfs/specs repository](http://github.com/ipfs/specs)\n\n## Lead Maintainer <!-- omit in toc -->\n\n[Alex Potsides](https://github.com/achingbrain)\n\n## Table of Contents <!-- omit in toc -->\n\n- [Install](#install)\n  - [npm](#npm)\n  - [Use in Node.js](#use-in-nodejs)\n  - [Use in a browser with browserify, webpack or any other bundler](#use-in-a-browser-with-browserify-webpack-or-any-other-bundler)\n  - [Use in a browser Using a script tag](#use-in-a-browser-using-a-script-tag)\n- [Usage](#usage)\n  - [Examples](#examples)\n    - [Create a file composed by several blocks](#create-a-file-composed-by-several-blocks)\n    - [Create a directory that contains several files](#create-a-directory-that-contains-several-files)\n- [API](#api)\n    - [UnixFS Data Structure](#unixfs-data-structure)\n    - [create an unixfs Data element](#create-an-unixfs-data-element)\n    - [add and remove a block size to the block size list](#add-and-remove-a-block-size-to-the-block-size-list)\n    - [get total fileSize](#get-total-filesize)\n    - [marshal and unmarshal](#marshal-and-unmarshal)\n    - [is this UnixFS entry a directory?](#is-this-unixfs-entry-a-directory)\n    - [has an mtime been set?](#has-an-mtime-been-set)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n### npm\n\n```sh\n> npm i ipfs-unixfs\n```\n\n### Use in Node.js\n\n```JavaScript\nvar UnixFS = require('ipfs-unixfs')\n```\n\n### Use in a browser with browserify, webpack or any other bundler\n\nThe code published to npm that gets loaded on require is in fact a ES5 transpiled version with the right shims added. This means that you can require it and use with your favourite bundler without having to adjust asset management process.\n\n```JavaScript\nvar UnixFS = require('ipfs-unixfs')\n```\n\n### Use in a browser Using a script tag\n\nLoading this module through a script tag will make the `UnixFS` obj available in the global namespace.\n\n```html\n<script src=\"https://npmcdn.com/ipfs-unixfs/dist/index.min.js\"></script>\n<!-- OR -->\n<script src=\"https://npmcdn.com/ipfs-unixfs/dist/index.js\"></script>\n```\n\n## Usage\n\n### Examples\n\n#### Create a file composed by several blocks\n\n```JavaScript\nconst data = new UnixFS({ type: 'file' })\ndata.addBlockSize(256) // add the size of each block\ndata.addBlockSize(256)\n// ...\n```\n\n#### Create a directory that contains several files\n\nCreating a directory that contains several files is achieve by creating a unixfs element that identifies a MerkleDAG node as a directory. The links of that MerkleDAG node are the files that are contained in this directory.\n\n```JavaScript\nconst data = new UnixFS({ type: 'directory' })\n```\n\n## API\n\n#### UnixFS Data Structure\n\n```protobuf\nsyntax = \"proto2\";\n\nmessage Data {\n  enum DataType {\n    Raw = 0;\n    Directory = 1;\n    File = 2;\n    Metadata = 3;\n    Symlink = 4;\n    HAMTShard = 5;\n  }\n\n  required DataType Type = 1;\n  optional bytes Data = 2;\n  optional uint64 filesize = 3;\n  repeated uint64 blocksizes = 4;\n  optional uint64 hashType = 5;\n  optional uint64 fanout = 6;\n  optional uint32 mode = 7;\n  optional UnixTime mtime = 8;\n}\n\nmessage UnixTime {\n  required int64 Seconds = 1;\n  optional fixed32 FractionalNanoseconds = 2;\n}\n\nmessage Metadata {\n  optional string MimeType = 1;\n}\n```\n\n#### create an unixfs Data element\n\n```JavaScript\nconst data = new UnixFS([options])\n```\n\n`options` is an optional object argument that might include the following keys:\n\n- type (string, default `file`): The type of UnixFS entry.  Can be:\n  - `raw`\n  - `directory`\n  - `file`\n  - `metadata`\n  - `symlink`\n  - `hamt-sharded-directory`\n- data (Uint8Array): The optional data field for this node\n- blockSizes (Array, default: `[]`): If this is a `file` node that is made up of multiple blocks, `blockSizes` is a list numbers that represent the size of the file chunks stored in each child node. It is used to calculate the total file size.\n- mode (Number, default `0644` for files, `0755` for directories/hamt-sharded-directories) file mode\n- mtime (`Date`, `{ secs, nsecs }`, `{ Seconds, FractionalNanoseconds }`, `[ secs, nsecs ]`): The modification time of this node\n\n#### add and remove a block size to the block size list\n\n```JavaScript\ndata.addBlockSize(<size in bytes>)\n```\n\n```JavaScript\ndata.removeBlockSize(<index>)\n```\n\n#### get total fileSize\n\n```JavaScript\ndata.fileSize() // => size in bytes\n```\n\n#### marshal and unmarshal\n\n```javascript\nconst marshaled = data.marshal()\nconst unmarshaled = Unixfs.unmarshal(marshaled)\n```\n\n#### is this UnixFS entry a directory?\n\n```JavaScript\nconst dir = new Data({ type: 'directory' })\ndir.isDirectory() // true\n\nconst file = new Data({ type: 'file' })\nfile.isDirectory() // false\n```\n\n#### has an mtime been set?\n\nIf no modification time has been set, no `mtime` property will be present on the `Data` instance:\n\n```JavaScript\nconst file = new Data({ type: 'file' })\nfile.mtime // undefined\n\nObject.prototype.hasOwnProperty.call(file, 'mtime') // false\n\nconst dir = new Data({ type: 'dir', mtime: new Date() })\ndir.mtime // { secs: Number, nsecs: Number }\n```\n\n## Contribute\n\nFeel free to join in. All welcome. Open an [issue](https://github.com/ipfs/js-ipfs-unixfs/issues)!\n\nThis repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/contributing.md)\n\n## License\n\n[MIT](LICENSE)\n","readmeFilename":"README.md","_id":"ipfs-unixfs@1.0.3-rc.3","_nodeVersion":"12.18.3","_npmVersion":"lerna/3.22.1/node@v12.18.3+x64 (linux)","dist":{"integrity":"sha512-phEldYrPTv7Y83aNsXlr5gCspSlYW+LnbY7kmA+plK70ljrQxClRCbAY+uogpc9TvfjGZo0Mo7HFNHiL7+mroQ==","shasum":"8e7d87bdcdb3010ff25c502452e0005440d7919e","tarball":"http://registry-npm.ywwl.com/ipfs-unixfs/download/ipfs-unixfs-1.0.3-rc.3.tgz","fileCount":13,"unpackedSize":33657,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfIAetCRA9TVsSAnZWagAAuikP/jYI7mk+EhwFFrbKqaMw\nJCF30cDwNXMZghbTKHrO6b4EXhES0KoX8+bZVicT28euNIJ8z/hUiXvd0p63\neUxL59INYftX5QG+RFUtMWe043jDCxUxtC90G6pkToyrSze/GwpGd+cg6ioy\nXI8/NNIpKc+Rt37VSMp935pRQ7/2KlE5+Q79XXnd5jJsATGQEt7IKk9Vuydp\nZtYXAIaDSV8lQf/5cuWFY3i7jpzrry0HIDOlZ1Vrrt08TMWu59yIxHNPgTPB\n3LtBrLdc+hUorZv4ROKrO402MIw2SILs31ezdlKrrSPriz/H7D8lrFkdU29r\nmoNg/PLKy1UYcaxWp/P64rKf/9XhhYrUifvpzoLTeAAyzGHQTPmnL29I74MN\nqR1CitBCDTInZWA1gli+ag37PsXkHy6P72N9oelAA2mMc8xVGGWq8zISqC98\npmkI/iN8F8IX6uKx6TdOkemKIacXIwfPNzTnTAS3Lt2KFq9sA8boxAvFXT+4\nH+OamXxudc+tlEpQ8Fa9VsL5LcH8shII/OOpeTSwBYCau+YS38NXJ6kuSM3o\nRPvnLA98pg8CGtvgShP8Xd2/vmRXYIZOubOH4PMLXmPBbPhod65jvY2tFIUj\nW+bx8yt/2d4GUx3Ct7N81BYeHbxU145++Dq+lDxgCBE3NG4pWmJt48+IXGma\nJoyv\r\n=dye8\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCJghFSHWs2+Y0Cxsi9049esWm6DMl34deR7KiTWtaMxAIhAMU+jkqp8IyXsPf9rEeuPBLL1uX1a5H1kG5YxUUMoBmu"}],"size":8582,"noattachment":false,"key":"/ipfs-unixfs/-/ipfs-unixfs-1.0.3-rc.3.tgz"},"maintainers":[{"email":"alex@achingbrain.net","name":"achingbrain"},{"email":"mail@daviddias.me","name":"daviddias"},{"email":"infra-accounts@protocol.ai","name":"ipfsbot"}],"_npmUser":{"name":"ipfsbot","email":"infra-accounts@protocol.ai"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ipfs-unixfs_1.0.3-rc.3_1595934637342_0.9991923926348161"},"_hasShrinkwrap":false,"publish_time":1595934637498,"_cnpm_publish_time":1595934637498,"dist-tags":{"latest":"13.1.2","next":"6.0.7-rc.5"}}