import * as dagPB from "@ipld/dag-pb";
import { decodeCID } from "../common/cid.js";
export const toDAGLink = (link) => {
    const { name, cid, size } = link;
    return dagPB.createLink(name, size, decodeCID(cid));
};
export const fromFSFile = (fsObj) => {
    const { name = "", cid, size, type } = fsObj;
    return {
        name,
        cid: cid,
        size,
        isFile: type !== "dir"
    };
};
export const fromDAGLink = (link) => {
    const name = link.Name || "";
    const cid = link.Hash;
    const size = link.Tsize || 0;
    return { name, cid, size };
};
export const make = (name, cid, isFile, size) => {
    return {
        name,
        cid,
        size,
        isFile
    };
};
export const arrToMap = (arr) => {
    return arr.reduce((acc, cur) => {
        acc[cur.name] = cur;
        return acc;
    }, {});
};
//# sourceMappingURL=link.js.map