{"name":"ipfs-unixfs","version":"2.0.3-rc.0","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":"^26.0.0","nyc":"^15.0.0","uint8arrays":"^1.1.0"},"dependencies":{"err-code":"^2.0.0","protons":"^2.0.0"},"gitHead":"2bf5d07d2fa6ade7404374a46647d5f852905993","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@2.0.3-rc.0","_nodeVersion":"12.18.3","_npmVersion":"lerna/3.22.1/node@v12.18.3+x64 (linux)","dist":{"integrity":"sha512-ZmUREpFdh2qvEYnDtX4pXVTKPd68FwBvgcekWIC7F/8H5S0ZetYoHrHYT5O27RCmXLNYUNGYHKtRP7tpnrc/iA==","shasum":"d48870269b4f861a7f6c043a2af3ece6a5c5a9dc","tarball":"http://registry-npm.ywwl.com/ipfs-unixfs/download/ipfs-unixfs-2.0.3-rc.0.tgz","fileCount":6,"unpackedSize":21018,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfRPXlCRA9TVsSAnZWagAAc8IP/i+n9e8ouyu2JQKfuxFt\nNjUG4byzkRVb2ERK7TPyMWY2ane1u1F3V4gdOSlsFOOIN1PsPk75dUP9u3vB\nA6JAlieyxZKAENArIi1vvfVDw5pu+k445uFfYIyZY+OLzV8K7/5O3F+T3Diy\nV34tiSfh6zNAQU1fHfk9n9UMPeJdPm5pYS0A4//nGYA4XxYlRco85a5XfLVZ\ngouMG7N6oXVY9SKDXbfjZq1FjbYvZtRbkg6sjJ1z7s6vkN3YirndSLK96LT9\n4+X3wQov30DMpl1fr6IsyP/R/zDfKpJ2heFj/B12BtHPzE1txMxYK0Nc/4CL\nKAy6keAqF5m9xXU4C2Ah1R4//HDSIiWaJpa26mmOW8IILjfOGDObx8lWkNkY\nAaXJlLpl5vSVs/MFu+y/OCmRz1EN4nY6kCYxTvct7dV/j2znGUj4+De4QczM\nZxRYBf8pcYPlAY3UISMV2hSCqYI6t07+IYuJYB0eKY1ixXZR5FlBAQTGliLV\n8FRLC47v+OeesJjotfh1weAD3K3F8SWnNzAXtGTdvhFeMrxLIEqVkj1sLi4i\nKhsFk9kw3zyriJGfG3RY6KuGAxejJ/By/NPMWuAyco9QaK0QVzzskG5Emy27\nltYf69zdgC8v8MgEcFLXB7wXkxEHcbDjU3oconEGQt64Mn0Xn+JG5bW8IA8b\nlD3D\r\n=xAFk\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDYwubAXQlrxQ3ard7yB809LrAxqqRSSFGM6aLy00lkeQIgDuMsQJ24B/l0q1zzR6y5oINJHeUIe/YM4+C6ktl00w4="}],"size":6976,"noattachment":false,"key":"/ipfs-unixfs/-/ipfs-unixfs-2.0.3-rc.0.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_2.0.3-rc.0_1598354916885_0.508722618887747"},"_hasShrinkwrap":false,"publish_time":1598354916985,"_cnpm_publish_time":1598354916985,"dist-tags":{"latest":"13.1.2","next":"6.0.7-rc.5"}}