Skip to content

Commit a86560a

Browse files
committed
update readme .travis.yml
1 parent b20d7e2 commit a86560a

File tree

2 files changed

+115
-4
lines changed

2 files changed

+115
-4
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ node_js:
44
- '5'
55
- stable
66

7+
# always use npm latest
8+
before_install:
9+
- npm i -g npm
10+
711
addons:
812
firefox: 'latest'
913

README.md

Lines changed: 111 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,120 @@
1-
ipfs-unixfs
2-
===========
1+
ipfs-unixfs JavaScript Implementation
2+
=====================================
33

44
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
5-
[[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
6-
[![Build Status](https://travis-ci.org/ipfs/js-ipfs-unixfs.svg?style=flat-square)](https://travis-ci.org/ipfs/js-ipfs-unixfs)
5+
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
6+
[![Build Status](https://travis-ci.org/ipfs/js-ipfs-unixfs.svg?style=flat-square&branch=master)](https://travis-ci.org/ipfs/js-ipfs-unixfs)
77
![](https://img.shields.io/badge/coverage-%3F%25-yellow.svg?style=flat-square)
88
[![Dependency Status](https://david-dm.org/ipfs/js-ipfs-unixfs.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfs-unixfs)
99
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
1010

1111
> JavaScript implementation of IPFS' unixfs (a Unix FileSystem representation on top of a MerkleDAG)
1212
13+
[The unixfs spec can be found inside the ipfs/specs repository](http://github.com/ipfs/specs)
14+
15+
# Installation
16+
17+
## npm
18+
19+
```sh
20+
> npm i ipfs-unixfs
21+
```
22+
23+
## Use in Node.js
24+
25+
```JavaScript
26+
var Unixfs = require('ipfs-unixfs')
27+
```
28+
29+
## Use in a browser with browserify, webpack or any other bundler
30+
31+
The 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.
32+
33+
```JavaScript
34+
var Unixfs = require('ipfs-unixfs')
35+
```
36+
37+
## Use in a browser Using a script tag
38+
39+
Loading this module through a script tag will make the `Unixfs` obj available in the global namespace.
40+
41+
```html
42+
<script src="URL/"></script>
43+
```
44+
1345
# Usage
46+
47+
## Examples
48+
49+
#### Create a file composed by several blocks
50+
51+
```JavaScript
52+
var data = new UnixFS('file')
53+
data.addBlockSize(256) // add the size of each block
54+
data.addBlockSize(256)
55+
// ...
56+
```
57+
58+
#### Create a directory that contains several files
59+
60+
Creating 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.
61+
62+
```JavaScript
63+
var data = new Unixfs('directory')
64+
```
65+
66+
## API
67+
68+
#### unixfs Data Structure
69+
70+
```protobuf
71+
message Data {
72+
enum DataType {
73+
Raw = 0;
74+
Directory = 1;
75+
File = 2;
76+
Metadata = 3;
77+
Symlink = 4;
78+
}
79+
80+
required DataType Type = 1;
81+
optional bytes Data = 2;
82+
optional uint64 filesize = 3;
83+
repeated uint64 blocksizes = 4;
84+
}
85+
86+
message Metadata {
87+
required string MimeType = 1;
88+
}
89+
```
90+
91+
#### create an unixfs Data element
92+
93+
```JavaScript
94+
var data = new UnixFS(<type>, [<content>])
95+
```
96+
97+
Type can be: `['raw', 'directory', 'file', 'metadata', 'symlink']`
98+
99+
#### add and remove a block size to the block size list
100+
101+
```JavaScript
102+
data.addBlockSize(<size in bytes>)
103+
```
104+
105+
```JavaScript
106+
data.removeBlockSize(<index>)
107+
```
108+
109+
#### get total fileSize
110+
111+
```JavaScript
112+
data.fileSize() // => size in bytes
113+
```
114+
115+
#### marshal and unmarshal
116+
117+
```
118+
var marsheled = data.marshal()
119+
var unmarsheled = Unixfs.unmarshal(marsheled)
120+
```

0 commit comments

Comments
 (0)