Problems displaying .tar file contents

Hello everyone, I’m still doing a lot of tests to learn how to use ipfs … but many things escape me, such as this:

I added a .tar file in my node

ipfs add myfolderA_2.tar
added QmZ3HkzboRFtfApNLN7SvYuVMzh9EnTX837iTBkXZuDX53 myfolderA_2.tar

ipfs ls , displays nothing, ipfs cat instead displays a strange format:

ipfs cat QmZ3HkzboRFtfApNLN7SvYuVMzh9EnTX837iTBkXZuDX53
myfolderA_2/0000775000175000017500000000000014402411573011360 5ustar  maxmaxmyfolderA_2/testipfs4.txt0000664000175000017500000000004114402411573014041 0ustar  maxmaxV4Y5xX6fFUYzFozWYqax8l3851kGWi3K
myfolderA_2/testipfs23.txt0000664000175000017500000000004114402411573014122 0ustar  maxmaxtxKpkMdGZA477L4BQqpMY1H3Rqbr0Rd4
myfolderA_2/testipfs19.txt0000664000175000017500000000004114402411573014127 0ustar  maxmaxTzExl0ozp06lNu0kjBW2RSASMqttx6wv
.....

It doesn’t look like proper coding. Can you help me understand?

Thank you.

ipfs add myfolderA_2.tar literally adds the binary tar format in IPFS, it does not unpack it into the underlying directory folder structure.
That why ipfs ls shows nothing, you are trying to ls a file, IPFS it does not parse the archive, for all that it knows that just a file made of some bytes like any other file. :slight_smile:
The thing you ipfs cated is a USTAR - OSDev Wiki tar format, you are viewing the raw bytes of the archive as expected.

The simplest way to get the structure is to first unpack the tar file and then add that to ipfs tar -xvf myfolderA_2.tar then ipfs add -r the unpacked folders / files. It would be on the easier side easy to make a script that streams the tar to something like mfs if you want to avoid unpacking it temporarly.

Thank you for answering me. I explain to you. This arises from the need to recursively copy a folder to a remote node via CURL using the ipfs API, apparently you can’t send cards to ipfs via curl. I had read somewhere that switching to ipfs with CURL a TAR file would then have the possibility to browse the contents with “ipfs ls”. Can you give me some advice on how to send a folder to a remote node using CURL?

You have the API here: Kubo RPC API | IPFS Docs

It’s not using a tar file and I don’t think you can send one, ipfs get use a tar file under the hood over http, so if you use the API you can keep the tar file and don’t unpack it, I don’t think that works with ipfs add altho that seems like a fine addition.

With curl it is not possible to send a folder with its contents, one would have to create a trick … but I’m still too young with IPFS

ipfs add use multipart/form-data

A lazy way to accomplish this would be to utilize MFS. Do ipfs add per file you want to add, then do ipfs files cp & ipfs files mkdir to build the tree you want.

multipart/form-data is ideal, but if you’re blocked on that, my idea should get the job done.

kubo v0.17.0 introduced support for serializing UnixFS directories as a tar stream, via the internal HTTP gateway. Example here.

So you’d need to import the contents of the tar (and not the tar itself) in IPFS. Then from the client side, all you need is curl.

1 Like