// r.log
r.log(bs);
+ r.log(Buffer.from("abc"));
r.log(r.headersOut['Connection'] ?? '');
// r.variables
r.subrequest('/p/sub2', {method:'POST'}).then(reply => r.return(reply.status));
vod = r.subrequest('/p/sub3', reply => r.return(reply.status));
vod = r.subrequest('/p/sub4', {method:'POST'}, reply => r.return(reply.status));
- vod = r.subrequest('/p/sub5', {detached:true});
+ vod = r.subrequest(Buffer.from('/p/sub5'), {detached:true});
// Warning: vod = r.subrequest('/p/sub9', {detached:true}, reply => r.return(reply.status));
r.subrequest('/p/sub6', 'a=1&b=2').then(reply => r.return(reply.status,
JSON.stringify(JSON.parse(reply.responseBody ?? ''))));
s = fs.readFileSync('/path', 'utf8');
s = fs.readFileSync(Buffer.from('/path'), {encoding:'hex'});
+
+ fs.writeFileSync('/path', Buffer.from('abc'));
}
function qs_module(str: NjsByteString) {
* Writes a string to the error log on the error level of logging.
* @param message Message to log.
*/
- error(message: NjsStringLike): void;
+ error(message: NjsStringOrBuffer): void;
/**
* Finishes sending a response to the client.
*/
* The actual redirect happens after the handler execution is completed.
* @param uri Location to redirect to.
*/
- internalRedirect(uri: NjsStringLike): void;
+ internalRedirect(uri: NjsStringOrBuffer): void;
/**
* Writes a string to the error log on the info level of logging.
* @param message Message to log.
*/
- log(message: NjsStringLike): void;
+ log(message: NjsStringOrBuffer): void;
/**
* HTTP method.
*/
* @param status Respose status code.
* @param body Respose body.
*/
- return(status: number, body?: NjsStringLike): void;
+ return(status: number, body?: NjsStringOrBuffer): void;
/**
* Sends the HTTP headers to the client.
*/
- send(part: NjsStringLike): void;
+ send(part: NjsStringOrBuffer): void;
/**
* Sends the HTTP headers to the client.
*/
* @param options Subrequest options.
* @param callback Completion callback.
*/
- subrequest(uri: NjsStringLike, options: NginxSubrequestOptions & { detached: true }): void;
- subrequest(uri: NjsStringLike, options?: NginxSubrequestOptions | string): Promise<NginxHTTPRequest>;
- subrequest(uri: NjsStringLike, options: NginxSubrequestOptions & { detached?: false } | string,
+ subrequest(uri: NjsStringOrBuffer, options: NginxSubrequestOptions & { detached: true }): void;
+ subrequest(uri: NjsStringOrBuffer, options?: NginxSubrequestOptions | string): Promise<NginxHTTPRequest>;
+ subrequest(uri: NjsStringOrBuffer, options: NginxSubrequestOptions & { detached?: false } | string,
callback:(reply:NginxHTTPRequest) => void): void;
- subrequest(uri: NjsStringLike, callback:(reply:NginxHTTPRequest) => void): void;
+ subrequest(uri: NjsStringOrBuffer, callback:(reply:NginxHTTPRequest) => void): void;
/**
* Current URI in request, normalized.
*/
* Writes a string to the error log on the warn level of logging.
* @param message Message to log.
*/
- warn(message: NjsStringLike): void;
+ warn(message: NjsStringOrBuffer): void;
}
* Writes a string to the error log on the error level of logging.
* @param message Message to log.
*/
- error(message: NjsStringLike): void;
+ error(message: NjsStringOrBuffer): void;
/**
* Writes a string to the error log on the info level of logging.
* @param message Message to log.
*/
- log(message: NjsStringLike): void;
+ log(message: NjsStringOrBuffer): void;
/**
* Unregisters the callback set by on() method.
*/
* @param options Object used to override nginx buffer flags derived from
* an incoming data chunk buffer.
*/
- send(data: NjsStringLike, options?: NginxStreamSendOptions): void;
+ send(data: NjsStringOrBuffer, options?: NginxStreamSendOptions): void;
/**
* nginx variables object.
*/
* Writes a string to the error log on the warn level of logging.
* @param message Message to log.
*/
- warn(message: NjsStringLike): void;
+ warn(message: NjsStringOrBuffer): void;
}
writeFloatLE(value: number, offset?: number): number;
}
+type NjsStringOrBuffer = NjsStringLike | Buffer | DataView | TypedArray;
// Global objects
/**
* Updates the hash content with the given `data` and returns self.
*/
- update(data: NjsStringLike | Buffer | DataView | TypedArray): Hash;
+ update(data: NjsStringOrBuffer): Hash;
/**
* Calculates the digest of all of the data passed using `hash.update()`.
/**
* Updates the HMAC content with the given `data` and returns self.
*/
- update(data: NjsStringLike | Buffer | DataView | TypedArray): Hmac;
+ update(data: NjsStringOrBuffer): Hmac;
/**
* Calculates the HMAC digest of all of the data passed using `hmac.update()`.
* @param key The secret key.
* @returns An `HMAC` object.
*/
- createHmac(algorithm: Algorithm, key: NjsStringLike): Hmac;
+ createHmac(algorithm: Algorithm, key: NjsStringOrBuffer): Hmac;
}
const crypto: Crypto;
* If `mode` is not supplied, the default of `0o666` is used.
* If `flag` is not supplied, the default of `'a'` is used.
*/
- appendFile(path: PathLike, data: NjsStringLike | Buffer, options?: WriteFileOptions): Promise<void>;
+ appendFile(path: PathLike, data: NjsStringOrBuffer, options?: WriteFileOptions): Promise<void>;
/**
* Asynchronously creates a directory at the specified `path`.
* If `mode` is not supplied, the default of `0o666` is used.
* If `flag` is not supplied, the default of `'w'` is used.
*/
- writeFile(path: PathLike, data: NjsStringLike | Buffer, options?: WriteFileOptions): Promise<void>;
+ writeFile(path: PathLike, data: NjsStringOrBuffer, options?: WriteFileOptions): Promise<void>;
}
interface NjsFS {
* If `mode` is not supplied, the default of `0o666` is used.
* If `flag` is not supplied, the default of `'a'` is used.
*/
- appendFileSync(path: PathLike, data: NjsStringLike | Buffer, options?: WriteFileOptions): void;
+ appendFileSync(path: PathLike, data: NjsStringOrBuffer, options?: WriteFileOptions): void;
/**
* Synchronously creates a directory at the specified `path`.
* If `mode` is not supplied, the default of `0o666` is used.
* If `flag` is not supplied, the default of `'w'` is used.
*/
- writeFileSync(path: PathLike, data: NjsStringLike | Buffer, options?: WriteFileOptions): void;
+ writeFileSync(path: PathLike, data: NjsStringOrBuffer, options?: WriteFileOptions): void;
}
const fs: NjsFS;