Skip to content

Commit

Permalink
Merge pull request #214 from GordonSmith/REFACTOR_UTILS
Browse files Browse the repository at this point in the history
chore: Minor tweaks to graphviz refactor
  • Loading branch information
GordonSmith authored Jan 17, 2024
2 parents c7c5b8e + 7861b31 commit 4d333d8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
9 changes: 6 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
"version": "0.2.0",
"configurations": [
{
"name": "index.html",
"name": "index-browser",
"type": "msedge",
"request": "launch",
"url": "http://localhost:8000/index.html",
"runtimeArgs": [],
"webRoot": "${workspaceRoot}"
"webRoot": "${workspaceRoot}",
"sourceMapPathOverrides": {
"webpack:///./*": "${workspaceRoot}/*",
"webpack:///*": "/*"
},
},
{
"name": "file:///index.html",
Expand Down
2 changes: 0 additions & 2 deletions src-cpp/graphviz/main.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#include <string>
#include "util.hpp"

class Graphviz
{
private:
public:
static const char *version();
static const char *lastError();
Expand Down
10 changes: 6 additions & 4 deletions src-cpp/graphviz/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ TempFileBuffer::operator std::string() const
if (filePointer != nullptr)
{
std::rewind(filePointer);
char buffer[256];
size_t bytesRead;
while ((bytesRead = std::fread(buffer, 1, sizeof(buffer), filePointer)) > 0)
content.append(buffer, bytesRead);
std::fseek(filePointer, 0, SEEK_END);
long fileSize = std::ftell(filePointer);
std::rewind(filePointer);

content.resize(fileSize);
std::fread(&content[0], 1, fileSize, filePointer);
}
return content;
}
6 changes: 6 additions & 0 deletions src-cpp/graphviz/util.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <string>
#include <cstdio>

class StringBuffer
{
Expand All @@ -23,6 +24,11 @@ class TempFileBuffer
TempFileBuffer();
~TempFileBuffer();

TempFileBuffer(const TempFileBuffer &) = delete;
TempFileBuffer(TempFileBuffer &&) = delete;
TempFileBuffer &operator=(const TempFileBuffer &) = delete;
TempFileBuffer &operator=(TempFileBuffer &&) = delete;

operator FILE *() const;
operator std::string() const;
operator const char *() const;
Expand Down
1 change: 0 additions & 1 deletion src-ts/__tests__/base91.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ describe("base91", function () {

const base91 = await Base91.load();
const base91Str = base91.encode(compressed_data);
console.log(data.byteLength, base91Str.length);
const compressed_data2 = base91.decode(base91Str);
expect(compressed_data).to.deep.equal(compressed_data2);

Expand Down

0 comments on commit 4d333d8

Please sign in to comment.