mirror of https://github.com/coder/code-server.git
Fix images not appearing (iconv encoding issue)
Fixed by returning the original buffer from `fs.read` and then just using whatever encoding was passed in to iconv, so this should all work exactly the same now as it does on native Node.
This commit is contained in:
parent
20c0fc4c52
commit
3bacbca325
|
@ -407,13 +407,12 @@ class FS {
|
||||||
return util.promisify(fs.read)(fd, buffer, 0, length, position).then((resp) => {
|
return util.promisify(fs.read)(fd, buffer, 0, length, position).then((resp) => {
|
||||||
return {
|
return {
|
||||||
bytesRead: resp.bytesRead,
|
bytesRead: resp.bytesRead,
|
||||||
content: (resp.bytesRead < buffer.length ? buffer.slice(0, resp.bytesRead) : buffer).toString("utf8"),
|
content: resp.bytesRead < buffer.length ? buffer.slice(0, resp.bytesRead) : buffer,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}, fd, length, position).then((resp) => {
|
}, fd, length, position).then((resp) => {
|
||||||
const newBuf = Buffer.from(resp.content, "utf8");
|
buffer.set(resp.content, offset);
|
||||||
buffer.set(newBuf, offset);
|
callback(undefined!, resp.bytesRead, resp.content as TBuffer);
|
||||||
callback(undefined!, resp.bytesRead, newBuf as TBuffer);
|
|
||||||
}).catch((ex) => {
|
}).catch((ex) => {
|
||||||
callback(ex, undefined!, undefined!);
|
callback(ex, undefined!, undefined!);
|
||||||
});
|
});
|
||||||
|
|
|
@ -57,39 +57,43 @@ export const stringify = (arg: any, isError?: boolean): string => { // tslint:di
|
||||||
* Parse an event argument.
|
* Parse an event argument.
|
||||||
*/
|
*/
|
||||||
export const parse = (arg: string): any => { // tslint:disable-line no-any
|
export const parse = (arg: string): any => { // tslint:disable-line no-any
|
||||||
if (!arg) {
|
const convert = (value: any): any => { // tslint:disable-line no-any
|
||||||
return arg;
|
if (value && value.data && value.type) {
|
||||||
}
|
switch (value.type) {
|
||||||
|
// JSON.stringify turns a Buffer into an object but JSON.parse doesn't
|
||||||
const result = JSON.parse(arg);
|
// turn it back, it just remains an object.
|
||||||
|
case "Buffer":
|
||||||
if (result && result.data && result.type) {
|
if (Array.isArray(value.data)) {
|
||||||
switch (result.type) {
|
return Buffer.from(value);
|
||||||
// JSON.stringify turns a Buffer into an object but JSON.parse doesn't
|
|
||||||
// turn it back, it just remains an object.
|
|
||||||
case "Buffer":
|
|
||||||
if (Array.isArray(result.data)) {
|
|
||||||
return Buffer.from(result);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
// Errors apparently can't be stringified, so we do something similar to
|
|
||||||
// what happens to buffers and stringify them as regular objects.
|
|
||||||
case "Error":
|
|
||||||
if (result.data.message) {
|
|
||||||
const error = new Error(result.data.message);
|
|
||||||
// TODO: Can we set the stack? Doing so seems to make it into an
|
|
||||||
// "invalid object".
|
|
||||||
if (typeof result.data.code !== "undefined") {
|
|
||||||
(error as NodeJS.ErrnoException).code = result.data.code;
|
|
||||||
}
|
}
|
||||||
// tslint:disable-next-line no-any
|
break;
|
||||||
(error as any).originalStack = result.data.stack;
|
// Errors apparently can't be stringified, so we do something similar to
|
||||||
|
// what happens to buffers and stringify them as regular objects.
|
||||||
|
case "Error":
|
||||||
|
if (value.data.message) {
|
||||||
|
const error = new Error(value.data.message);
|
||||||
|
// TODO: Can we set the stack? Doing so seems to make it into an
|
||||||
|
// "invalid object".
|
||||||
|
if (typeof value.data.code !== "undefined") {
|
||||||
|
(error as NodeJS.ErrnoException).code = value.data.code;
|
||||||
|
}
|
||||||
|
// tslint:disable-next-line no-any
|
||||||
|
(error as any).originalStack = value.data.stack;
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
if (value && typeof value === "object") {
|
||||||
|
Object.keys(value).forEach((key) => {
|
||||||
|
value[key] = convert(value[key]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
|
||||||
|
return arg ? convert(JSON.parse(arg)) : arg;
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,6 +19,12 @@ export const evaluate = (connection: SendableConnection, message: NewEvalMessage
|
||||||
*/
|
*/
|
||||||
// tslint:disable-next-line no-any
|
// tslint:disable-next-line no-any
|
||||||
const sendResp = (resp: any): void => {
|
const sendResp = (resp: any): void => {
|
||||||
|
logger.trace(() => [
|
||||||
|
"resolve",
|
||||||
|
field("id", message.getId()),
|
||||||
|
field("response", stringify(resp)),
|
||||||
|
]);
|
||||||
|
|
||||||
const evalDone = new EvalDoneMessage();
|
const evalDone = new EvalDoneMessage();
|
||||||
evalDone.setId(message.getId());
|
evalDone.setId(message.getId());
|
||||||
evalDone.setResponse(stringify(resp));
|
evalDone.setResponse(stringify(resp));
|
||||||
|
@ -34,6 +40,12 @@ export const evaluate = (connection: SendableConnection, message: NewEvalMessage
|
||||||
* Send an exception and call onDispose.
|
* Send an exception and call onDispose.
|
||||||
*/
|
*/
|
||||||
const sendException = (error: Error): void => {
|
const sendException = (error: Error): void => {
|
||||||
|
logger.trace(() => [
|
||||||
|
"reject",
|
||||||
|
field("id", message.getId()),
|
||||||
|
field("response", stringify(error, true)),
|
||||||
|
]);
|
||||||
|
|
||||||
const evalFailed = new EvalFailedMessage();
|
const evalFailed = new EvalFailedMessage();
|
||||||
evalFailed.setId(message.getId());
|
evalFailed.setId(message.getId());
|
||||||
evalFailed.setResponse(stringify(error, true));
|
evalFailed.setResponse(stringify(error, true));
|
||||||
|
|
|
@ -10,7 +10,7 @@ class IconvLiteDecoderStream extends Transform {
|
||||||
super(options);
|
super(options);
|
||||||
// tslint:disable-next-line no-any
|
// tslint:disable-next-line no-any
|
||||||
this.conv = (iconv as any).getDecoder(options.encoding, undefined);
|
this.conv = (iconv as any).getDecoder(options.encoding, undefined);
|
||||||
options.encoding = this.encoding = "utf8";
|
this.encoding = options.encoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
// tslint:disable-next-line no-any
|
// tslint:disable-next-line no-any
|
||||||
|
|
Loading…
Reference in New Issue