{"name":"ipfs-unixfs","version":"1.0.3-rc.1","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":"^22.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":"8e8d83d757276be7e1cb2581abd4b562cb8209e2","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 (Buffer): 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.1","_nodeVersion":"12.18.0","_npmVersion":"lerna/3.20.2/node@v12.18.0+x64 (linux)","dist":{"integrity":"sha512-4PkzLHybXDRXt3jjXJAdHKaSNFID1xQWOAv8vb0+S9VacDuOnaDOE0D4iA4gCGF5NEUpxL5iqxX25VomF+D3Og==","shasum":"27eed54dc1286a6db0789bacc1a67aa197dbc806","tarball":"http://registry-npm.ywwl.com/ipfs-unixfs/download/ipfs-unixfs-1.0.3-rc.1.tgz","fileCount":13,"unpackedSize":33653,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJe2NrNCRA9TVsSAnZWagAAxn4P/j7kGozQLyR7ml2nVXA9\nDO40QMKoRUdgbioY4MyKFsX2ZImhPLjmZvuxD6NZp87rje49p5j+u1g0DBb9\n4DI59GazTX3DB6BR9PYRohPMHYfS7doXgp+pw4Uu8PjcRJplkfUnPnzZA8/w\noiIC9OAeWjAqPbRqzgbui+tg0gNyHsr7iMCeq76gxSluZXqfFZIxEiA+nxj7\nn8d6o7p57H8THhiy1uWp5leOAgJ4lyl1aNuu+BRPYvv/28a+k1jY932T1fTl\nuMn7IAdmVv09+9LSJfIHxU1sfCVq5AcBSMHOI8E0s/0xDz6HFAYBvUjsH9CZ\nYq++eyAmQ8MRch+DqKCFEl7vaSyjqaIDPWZaS/lI8ZAoASlulyX7Beh1AjOx\nMG2VgZ3kMXcA4nAUcujLKUVM5fwR387yKp1zGeqcXOwAcIJs7kvSsRBEwV8m\nAm7c/MhwIhkt6jf9+I6woDV9GTW1xE317Pq0+NIGy1K3NY3h/+0s7AZ57WOk\nfv3oUzWurqT2JM53AVHMjKVnPoQid3TLjiiFflIXbkJsUqCZc9ldTMBPoJEA\neNu3sjpCDLtMsmTR+2VRVU6dfkBWk5/AqyoFV2lXmBWXVaXxWaOG3m+nsvQI\njPHP7AEKUD19zrf2RI7Mf0OYYlrVjHTVT1V+2f88der5+zNbJJ8bNohJjqHG\njoJ7\r\n=2vhQ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICusoHg/uCgV4AXVGK5A7TjzZTgvWeRM2AN5s5R9G/W1AiAkYJ4VfLfSPCP60rQiqySfBNR6yDtP++K5g5ihZ5/CpA=="}],"size":8579,"noattachment":false,"key":"/ipfs-unixfs/-/ipfs-unixfs-1.0.3-rc.1.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.1_1591270093295_0.2960399219862855"},"_hasShrinkwrap":false,"publish_time":1591270093459,"_cnpm_publish_time":1591270093459,"dist-tags":{"latest":"13.1.2","next":"6.0.7-rc.5"}}