const crypto = require("crypto"),
fs = require("fs"),
path = require("path");
const json = {
"sha": "4ef57de8e81c8415d6da2b267872e602b1f28cfe",
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/trees/4ef57de8e81c8415d6da2b267872e602b1f28cfe",
"tree": [
{
"path": ".coveragerc",
"mode": "100644",
"type": "blob",
"sha": "449170d0faeb75182310345564fd1811c0b9fd73",
"size": 163,
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/blobs/449170d0faeb75182310345564fd1811c0b9fd73"
},
{
"path": ".editorconfig",
"mode": "100644",
"type": "blob",
"sha": "75884936ea2d35b531af886acad747d4fd9b2a9e",
"size": 328,
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/blobs/75884936ea2d35b531af886acad747d4fd9b2a9e"
},
{
"path": ".flake8",
"mode": "100644",
"type": "blob",
"sha": "69e872e30d30f5c7de3276d289d6aee81ccf4af7",
"size": 232,
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/blobs/69e872e30d30f5c7de3276d289d6aee81ccf4af7"
},
{
"path": ".github",
"mode": "040000",
"type": "tree",
"sha": "56b49acad224fdb70fca11809f3e5a4d396cb01c",
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/trees/56b49acad224fdb70fca11809f3e5a4d396cb01c"
},
{
"path": ".gitignore",
"mode": "100644",
"type": "blob",
"sha": "4832b44b973574253cf1b59ba7a66cfc227cd699",
"size": 1439,
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/blobs/4832b44b973574253cf1b59ba7a66cfc227cd699"
},
{
"path": ".jshintrc",
"mode": "100644",
"type": "blob",
"sha": "939efa02939437adece1e3a076d597b2557e36b5",
"size": 319,
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/blobs/939efa02939437adece1e3a076d597b2557e36b5"
},
{
"path": ".travis.yml",
"mode": "100644",
"type": "blob",
"sha": "6b5e4f43790874e2cf9db23e964f72b99deeb0d1",
"size": 6040,
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/blobs/6b5e4f43790874e2cf9db23e964f72b99deeb0d1"
},
{
"path": "AUTHORS",
"mode": "100644",
"type": "blob",
"sha": "0b92b7759ce2dd0a7cacf79b273368bb71ac5397",
"size": 197,
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/blobs/0b92b7759ce2dd0a7cacf79b273368bb71ac5397"
},
{
"path": "CODE_OF_CONDUCT.md",
"mode": "100644",
"type": "blob",
"sha": "ae61c31efae6cea565e447467e4377da76125679",
"size": 2754,
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/blobs/ae61c31efae6cea565e447467e4377da76125679"
},
{
"path": "CONTRIBUTING.md",
"mode": "100644",
"type": "blob",
"sha": "ac71ad378faf7fb7ae927b20d4d28a57c6085bf9",
"size": 155,
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/blobs/ac71ad378faf7fb7ae927b20d4d28a57c6085bf9"
},
{
"path": "COPYING",
"mode": "100644",
"type": "blob",
"sha": "94a9ed024d3859793618152ea559a168bbcbb5e2",
"size": 35147,
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/blobs/94a9ed024d3859793618152ea559a168bbcbb5e2"
},
{
"path": "Gulpfile.js",
"mode": "100644",
"type": "blob",
"sha": "5dd951ae61f0913605197fafa018f7db49549a68",
"size": 6137,
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/blobs/5dd951ae61f0913605197fafa018f7db49549a68"
},
{
"path": "LICENSE",
"mode": "100644",
"type": "blob",
"sha": "8a171a155d85927b678068becd046194aea777a9",
"size": 717,
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/blobs/8a171a155d85927b678068becd046194aea777a9"
},
{
"path": "Makefile",
"mode": "100644",
"type": "blob",
"sha": "cc722c2bc71dfbaa1b025c8c56245ed0fcd61739",
"size": 3829,
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/blobs/cc722c2bc71dfbaa1b025c8c56245ed0fcd61739"
},
{
"path": "README.md",
"mode": "100644",
"type": "blob",
"sha": "a6a9013159a3766da62443c4be5e267435469fd9",
"size": 3280,
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/blobs/a6a9013159a3766da62443c4be5e267435469fd9"
},
{
"path": "assets",
"mode": "040000",
"type": "tree",
"sha": "1846a32450eb2a7605acb55cab8206028cfb656f",
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/trees/1846a32450eb2a7605acb55cab8206028cfb656f"
},
{
"path": "doc",
"mode": "040000",
"type": "tree",
"sha": "f55b804a2b694db577b20c8e9851ad783fea8ee5",
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/trees/f55b804a2b694db577b20c8e9851ad783fea8ee5"
},
{
"path": "errors",
"mode": "040000",
"type": "tree",
"sha": "b37a18162be2bdae7382fc194f1bf2d0ab89bba3",
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/trees/b37a18162be2bdae7382fc194f1bf2d0ab89bba3"
},
{
"path": "export-assets",
"mode": "040000",
"type": "tree",
"sha": "3a8b85efa969c389ac3c5e7e6ad62206dbddcaca",
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/trees/3a8b85efa969c389ac3c5e7e6ad62206dbddcaca"
},
{
"path": "fixtures",
"mode": "040000",
"type": "tree",
"sha": "89cacb4de6feb81a962b9a992b9434cb44d3b0aa",
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/trees/89cacb4de6feb81a962b9a992b9434cb44d3b0aa"
},
{
"path": "geodata",
"mode": "040000",
"type": "tree",
"sha": "635d29035ae7528231edb9b74eb09887c22dda2a",
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/trees/635d29035ae7528231edb9b74eb09887c22dda2a"
},
{
"path": "manage.py",
"mode": "100755",
"type": "blob",
"sha": "458f6e2df8b431b9fa819c89e82cebf2e0a91260",
"size": 1536,
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/blobs/458f6e2df8b431b9fa819c89e82cebf2e0a91260"
},
{
"path": "package.json",
"mode": "100644",
"type": "blob",
"sha": "02d231aa0c0fa299581be07bcece0393dc9a9e47",
"size": 1402,
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/blobs/02d231aa0c0fa299581be07bcece0393dc9a9e47"
},
{
"path": "quotes.txt",
"mode": "100644",
"type": "blob",
"sha": "e8e84a048d70bc57c1f725fc12f2101a40c5dcbb",
"size": 1552,
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/blobs/e8e84a048d70bc57c1f725fc12f2101a40c5dcbb"
},
{
"path": "requirements-dev.txt",
"mode": "100644",
"type": "blob",
"sha": "7297a894036fcf70a7209062bb51f45db1b71d39",
"size": 227,
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/blobs/7297a894036fcf70a7209062bb51f45db1b71d39"
},
{
"path": "requirements-prod.txt",
"mode": "100644",
"type": "blob",
"sha": "2f957115bcf3794fdecf3c4848f21ae8f428c31b",
"size": 83,
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/blobs/2f957115bcf3794fdecf3c4848f21ae8f428c31b"
},
{
"path": "requirements.txt",
"mode": "100644",
"type": "blob",
"sha": "805fefa566ef0d8f6a7c7e58d01fa4684078cf50",
"size": 998,
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/blobs/805fefa566ef0d8f6a7c7e58d01fa4684078cf50"
},
{
"path": "robots.txt",
"mode": "100644",
"type": "blob",
"sha": "8ca70253a4bb677cb797a7b409df4c4a9c0baa67",
"size": 948,
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/blobs/8ca70253a4bb677cb797a7b409df4c4a9c0baa67"
},
{
"path": "scripts",
"mode": "040000",
"type": "tree",
"sha": "f6a251faaaa14ba4fcf702cd0556675e70cc80f3",
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/trees/f6a251faaaa14ba4fcf702cd0556675e70cc80f3"
},
{
"path": "suggestions.txt",
"mode": "100644",
"type": "blob",
"sha": "5e5d11a62a00d3f1aea8f3825c8ec89860d31ad0",
"size": 285,
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/blobs/5e5d11a62a00d3f1aea8f3825c8ec89860d31ad0"
},
{
"path": "templates",
"mode": "040000",
"type": "tree",
"sha": "5b6dde8b8b616ba078305584e23e55ad0c5b2299",
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/trees/5b6dde8b8b616ba078305584e23e55ad0c5b2299"
},
{
"path": "update.md",
"mode": "100644",
"type": "blob",
"sha": "734cb67218ac7ad952ffe2f816e4820427efe809",
"size": 45743,
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/blobs/734cb67218ac7ad952ffe2f816e4820427efe809"
},
{
"path": "yarn.lock",
"mode": "100644",
"type": "blob",
"sha": "9fed208fbed286860cb606c9904eb3bab2b3d960",
"size": 193867,
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/blobs/9fed208fbed286860cb606c9904eb3bab2b3d960"
},
{
"path": "zds",
"mode": "040000",
"type": "tree",
"sha": "45b76aa70ad46e116c491a55def4b396b4ecba89",
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/trees/45b76aa70ad46e116c491a55def4b396b4ecba89"
},
{
"path": "zmd",
"mode": "040000",
"type": "tree",
"sha": "89289051d5d1e37ecc12629737d4fc01dd0df06e",
"url": "https://api.github.com/repos/zestedesavoir/zds-site/git/trees/89289051d5d1e37ecc12629737d4fc01dd0df06e"
}
],
"truncated": false
};
function pad(num, length) {
var pad = new Array(1 + length).join("0");
return (pad + num).slice(-pad.length);
}
let text = "";
for (let key in json.tree) {
if (json.tree.hasOwnProperty(key)) {
let blob = json.tree[key],
sha = Buffer.from(blob.sha, "hex").toString("binary");
text += blob.mode + " " + blob.path + "\0" + sha;
}
}
console.log("Original " + json.sha);
const pattern = "tree " + text.length + "\0" + text;
console.log("Actual : " + sha1(pattern));
function sha1(data) {
return crypto.createHash("sha1").update(data, "binary").digest("hex");
}