mirror of
https://git.tuxpa.in/a/code-server.git
synced 2024-12-26 12:15:26 +00:00
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,33 +57,28 @@ 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) {
|
||||||
|
|
||||||
const result = JSON.parse(arg);
|
|
||||||
|
|
||||||
if (result && result.data && result.type) {
|
|
||||||
switch (result.type) {
|
|
||||||
// JSON.stringify turns a Buffer into an object but JSON.parse doesn't
|
// JSON.stringify turns a Buffer into an object but JSON.parse doesn't
|
||||||
// turn it back, it just remains an object.
|
// turn it back, it just remains an object.
|
||||||
case "Buffer":
|
case "Buffer":
|
||||||
if (Array.isArray(result.data)) {
|
if (Array.isArray(value.data)) {
|
||||||
return Buffer.from(result);
|
return Buffer.from(value);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
// Errors apparently can't be stringified, so we do something similar to
|
// Errors apparently can't be stringified, so we do something similar to
|
||||||
// what happens to buffers and stringify them as regular objects.
|
// what happens to buffers and stringify them as regular objects.
|
||||||
case "Error":
|
case "Error":
|
||||||
if (result.data.message) {
|
if (value.data.message) {
|
||||||
const error = new Error(result.data.message);
|
const error = new Error(value.data.message);
|
||||||
// TODO: Can we set the stack? Doing so seems to make it into an
|
// TODO: Can we set the stack? Doing so seems to make it into an
|
||||||
// "invalid object".
|
// "invalid object".
|
||||||
if (typeof result.data.code !== "undefined") {
|
if (typeof value.data.code !== "undefined") {
|
||||||
(error as NodeJS.ErrnoException).code = result.data.code;
|
(error as NodeJS.ErrnoException).code = value.data.code;
|
||||||
}
|
}
|
||||||
// tslint:disable-next-line no-any
|
// tslint:disable-next-line no-any
|
||||||
(error as any).originalStack = result.data.stack;
|
(error as any).originalStack = value.data.stack;
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
@ -91,5 +86,14 @@ export const parse = (arg: string): any => { // tslint:disable-line no-any
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
Block a user