Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

feat: support UnixFSv1.5 metadata #1186

Merged
merged 13 commits into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 8 additions & 0 deletions src/add/form-data.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ exports.toFormData = async input => {
let i = 0

for await (const file of files) {
if (file.mtime) {
formData.append('mtime', file.mtime)
achingbrain marked this conversation as resolved.
Show resolved Hide resolved
}

if (file.mode) {
formData.append('mode', file.mode)
}

if (file.content) {
// In the browser there's _currently_ no streaming upload, buffer up our
// async iterator chunks and append a big Blob :(
Expand Down
8 changes: 8 additions & 0 deletions src/add/form-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ exports.toFormData = async input => {
let i = 0

for await (const file of files) {
if (file.mtime) {
formData.append(`file-${i}-mtime`, file.mtime)
achingbrain marked this conversation as resolved.
Show resolved Hide resolved
}

if (file.mode) {
formData.append(`file-${i}-mode`, file.mode)
}

if (file.content) {
// In Node.js, FormData can be passed a stream so no need to buffer
formData.append(
Expand Down
10 changes: 8 additions & 2 deletions src/add/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ module.exports = configure(({ ky }) => {
}
})

function toCoreInterface ({ name, hash, size }) {
return { path: name, hash, size: parseInt(size) }
function toCoreInterface ({ name, hash, size, mode, mtime }) {
return {
path: name,
hash,
size: parseInt(size),
mode: mode,
mtime: mtime
}
}
24 changes: 24 additions & 0 deletions src/files/chmod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict'

const configure = require('../lib/configure')

module.exports = configure(({ ky }) => {
return function chmod (path, mode, options) {
options = options || {}

const searchParams = new URLSearchParams(options.searchParams)
searchParams.append('arg', path)
searchParams.append('mode', mode)
if (options.format) searchParams.set('format', options.format)
if (options.flush != null) searchParams.set('flush', options.flush)
if (options.hashAlg) searchParams.set('hash', options.hashAlg)
if (options.parents != null) searchParams.set('parents', options.parents)

return ky.post('files/chmod', {
timeout: options.timeout,
signal: options.signal,
headers: options.headers,
searchParams
}).text()
}
})
29 changes: 29 additions & 0 deletions src/files/touch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict'

const configure = require('../lib/configure')

module.exports = configure(({ ky }) => {
return function touch (path, mtime, options) {
options = options || {}

if (isNaN(mtime)) {
options = mtime
mtime = null
}

const searchParams = new URLSearchParams(options.searchParams)
searchParams.append('arg', path)
if (mtime) searchParams.set('mtime', mtime)
if (options.format) searchParams.set('format', options.format)
if (options.flush != null) searchParams.set('flush', options.flush)
if (options.hashAlg) searchParams.set('hash', options.hashAlg)
if (options.parents != null) searchParams.set('parents', options.parents)

return ky.post('files/touch', {
timeout: options.timeout,
signal: options.signal,
headers: options.headers,
searchParams
}).text()
}
})