I'm retrieving a file from GitLab (which sends files base64 encoded) that contains the tree seen below:
$ tree
.
├── LICENSE.md
├── README.md
├── manifest.yaml
├── src
│ ├── workflow.yaml
│ ├── workflow.json
│ └── resources
│ ├── action1.yaml
│ ├── action2.yaml
│ ├── subworkflow.yaml
│ └── template.yaml
└── install
└── workflow.zip
How can I decode this and keep the special characters (└,├,─)?
I've tried straight decoding and converting the bytes to string:
def decode(data):
decoded = base64.b64decode(data)
return "".join(chr(x) for x in bytearray(decoded))
That gives the wrong characters:
$ tree
.
â??â??â?? LICENSE.md
â??â??â?? README.md
â??â??â?? manifest.yaml
â??â??â?? src
â??  â??â??â?? workflow.yaml
â??  â??â??â?? workflow.json
â??  â??â??â?? resources
â??  â??â??â?? action1.yaml
â??  â??â??â?? action2.yaml
â??  â??â??â?? subworkflow.yaml
â??  â??â??â?? template.yaml
â??â??â?? install
  â??â??â?? workflow.zip
Then tried converting to utf-8 bytes first, but that converts them to question marks:
def decode_data(b64_data):
b64_bytes = b64_data.encode('utf-8')
data_bytes = base64.b64decode(b64_bytes)
return data_bytes.decode('utf-8')
What else can I try? I'm using python3.6
Response for GitLab when retrieving the file:
{
"file_name": "README.md",
"file_path": "README.md",
"size": 390,
"encoding": "base64",
"content_sha256": "b3cbc43cae23d77e09b60a2cb89ce76b969024ba6621548b6d3bc5b2b60380da",
"ref": "master",
"blob_id": "b7d9985ac1378310d31b9a8bccfc2cce5ad9655a",
"commit_id": "bbc71c23657249a924174eca9b025d64b10518fc",
"last_commit_id": "bbc71c23657249a924174eca9b025d64b10518fc",
"content": "IyBUZXN0R2l0CgpgYGAKJCB0cmVlCi4K4pSc4pSA4pSAIExJQ0VOU0UubWQK4pSc4pSA4pSAIFJFQURNRS5tZArilJzilIDilIAgbWFuaWZlc3QueWFtbArilJzilIDilIAgc3JjCuKUgsKgwqAg4pSc4pSA4pSAIHdvcmtmbG93LnlhbWwK4pSCwqDCoCDilJzilIDilIAgd29ya2Zsb3cuanNvbgrilILCoMKgIOKUlOKUgOKUgCByZXNvdXJjZXMK4pSCwqDCoCAgICAg4pSc4pSA4pSAIGFjdGlvbjEueWFtbArilILCoMKgICAgICDilJzilIDilIAgYWN0aW9uMi55YW1sCuKUgsKgwqAgICAgIOKUnOKUgOKUgCBzdWJ3b3JrZmxvdy55YW1sCuKUgsKgwqAgICAgIOKUlOKUgOKUgCB0ZW1wbGF0ZS55YW1sCuKUlOKUgOKUgCBpbnN0YWxsCiDCoMKgIOKUlOKUgOKUgCB3b3JrZmxvdy56aXAKYGBg"
}