Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
language: node_js
cache: npm
stages:
- check
- test
- cov

node_js:
- '10'

os:
- linux
- osx
- windows

script: npx nyc -s npm run test:node -- --bail
after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov

jobs:
include:
- stage: check
script:
- npx aegir commitlint --travis
- npx aegir dep-check
- npm run lint

- stage: test
name: chrome
addons:
chrome: stable
script: npx aegir test -t browser

- stage: test
name: webworker
addons:
chrome: stable
script: npx aegir test -t webworker

- stage: test
name: firefox
addons:
firefox: latest
script: npx aegir test -t browser -- --browsers FirefoxHeadless

notifications:
email: false
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
[![Build Status](https://ci.ipfs.team/buildStatus/icon?job=ipfs/js-ipfs-mfs/master)](https://ci.ipfs.team/job/ipfs/job/js-ipfs-mfs/job/master/)
[![Build Status](https://flat.badgen.net/travis/ipfs/js-ipfs-mfs)](https://travis-ci.com/ipfs/js-ipfs-mfs)
[![Code Coverage](https://codecov.io/gh/ipfs/js-ipfs-mfs/branch/master/graph/badge.svg)](https://codecov.io/gh/ipfs/js-ipfs-mfs)
[![Dependency Status](https://david-dm.org/ipfs/js-ipfs-mfs.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfs-mfs)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
Expand Down
2 changes: 0 additions & 2 deletions ci/Jenkinsfile

This file was deleted.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"ipld-in-memory": "^2.0.0",
"multihashes": "~0.4.14",
"pull-buffer-stream": "^1.0.1",
"pull-traverse": "^1.0.3"
"pull-traverse": "^1.0.3",
"temp-write": "^3.4.0"
},
"dependencies": {
"async": "^2.6.1",
Expand Down
Binary file removed test/fixtures/large-file.jpg
Binary file not shown.
1 change: 0 additions & 1 deletion test/fixtures/small-file.txt

This file was deleted.

21 changes: 21 additions & 0 deletions test/helpers/random-bytes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict'

const crypto = require('crypto')
const MAX_BYTES = 65536

// One day this will be merged: https://github.com/crypto-browserify/randombytes/pull/16
module.exports = function randomBytes (num) {
const bytes = Buffer.allocUnsafe(num)

for (let offset = 0; offset < num; offset += MAX_BYTES) {
let size = MAX_BYTES

if ((offset + size) > num) {
size = num - offset
}

crypto.randomFillSync(bytes, offset, size)
}

return bytes
}
5 changes: 2 additions & 3 deletions test/read.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@
const chai = require('chai')
chai.use(require('dirty-chai'))
const expect = chai.expect
const path = require('path')
const loadFixture = require('aegir/fixtures')
const bufferStream = require('pull-buffer-stream')
const pull = require('pull-stream/pull')
const collect = require('pull-stream/sinks/collect')
const {
createMfs,
createShardedDirectory
} = require('./helpers')
const randomBytes = require('./helpers/random-bytes')

describe('read', () => {
let mfs
let smallFile = loadFixture(path.join('test', 'fixtures', 'small-file.txt'))
let smallFile = randomBytes(13)

before(async () => {
mfs = await createMfs()
Expand Down
7 changes: 3 additions & 4 deletions test/stat.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
const chai = require('chai')
chai.use(require('dirty-chai'))
const expect = chai.expect
const path = require('path')
const loadFixture = require('aegir/fixtures')
const randomBytes = require('./helpers/random-bytes')

const {
createMfs,
Expand All @@ -16,8 +15,8 @@ const {

describe('stat', () => {
let mfs
let smallFile = loadFixture(path.join('test', 'fixtures', 'small-file.txt'))
let largeFile = loadFixture(path.join('test', 'fixtures', 'large-file.jpg'))
let smallFile = randomBytes(13)
let largeFile = randomBytes(490668)

before(async () => {
mfs = await createMfs()
Expand Down
20 changes: 11 additions & 9 deletions test/write.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
const chai = require('chai')
chai.use(require('dirty-chai'))
const expect = chai.expect
const path = require('path')
const loadFixture = require('aegir/fixtures')
const isNode = require('detect-node')
const values = require('pull-stream/sources/values')
const bufferStream = require('pull-buffer-stream')
const multihash = require('multihashes')
const randomBytes = require('./helpers/random-bytes')
const util = require('util')
const {
collectLeafCids,
createMfs,
Expand All @@ -19,16 +19,17 @@ const {
} = require('./helpers')
const CID = require('cids')

let fs
let fs, tempWrite

if (isNode) {
fs = require('fs')
tempWrite = require('temp-write')
}

describe('write', () => {
let mfs
let smallFile = loadFixture(path.join('test', 'fixtures', 'small-file.txt'))
let largeFile = loadFixture(path.join('test', 'fixtures', 'large-file.jpg'))
let smallFile = randomBytes(13)
let largeFile = randomBytes(490668)

const runTest = (fn) => {
let i = 0
Expand Down Expand Up @@ -148,15 +149,16 @@ describe('write', () => {
}

const filePath = `/small-file-${Math.random()}.txt`
const pathToFile = path.resolve(path.join(__dirname, 'fixtures', 'small-file.txt'))
const pathToFile = await tempWrite(smallFile)
const fsStats = await util.promisify(fs.stat)(pathToFile)

await mfs.write(filePath, pathToFile, {
create: true
})

const stats = await mfs.stat(filePath)

expect(stats.size).to.equal(smallFile.length)
expect(stats.size).to.equal(fsStats.size)
})

it('writes part of a small file using a path (Node only)', async function () {
Expand All @@ -165,7 +167,7 @@ describe('write', () => {
}

const filePath = `/small-file-${Math.random()}.txt`
const pathToFile = path.resolve(path.join(__dirname, 'fixtures', 'small-file.txt'))
const pathToFile = await tempWrite(smallFile)

await mfs.write(filePath, pathToFile, {
create: true,
Expand All @@ -183,7 +185,7 @@ describe('write', () => {
}

const filePath = `/small-file-${Math.random()}.txt`
const pathToFile = path.resolve(path.join(__dirname, 'fixtures', 'small-file.txt'))
const pathToFile = await tempWrite(smallFile)
const stream = fs.createReadStream(pathToFile)

await mfs.write(filePath, stream, {
Expand Down