ndn-js: Blob and SignedBlob

This commit is contained in:
Junxiao Shi
2018-10-20 14:38:48 -04:00
parent 1fd1b537aa
commit 6baea0f9bf
3 changed files with 53 additions and 5 deletions

23
types/ndn-js/blob.d.ts vendored Normal file
View File

@@ -0,0 +1,23 @@
export class Blob {
constructor(value?: Blob);
constructor(value: Buffer, copy?: boolean);
constructor(value: number[]);
constructor(value: string);
size(): number;
buf(): Buffer;
isNull(): boolean;
toHex(): string;
toString(): string;
equals(other: Blob): boolean;
}
export class SignedBlob extends Blob {
constructor();
constructor(value: Blob|Buffer|number[], signedPortionBeginOffset: number, signedPortionEndOffset: number);
signedSize(): number;
signedBuf(): Buffer;
getSignedPortionBeginOffset(): number;
getSignedPortionEndOffset(): number;
}

View File

@@ -1,3 +1,4 @@
export as namespace ndn;
export * from "./blob";
export * from "./face";
export * from "./transport";

View File

@@ -1,7 +1,31 @@
/// <reference types="node"/>
import ndn = require("ndn-js");
let face = new ndn.Face();
face = new ndn.Face({host: 'hobo.cs.arizona.edu', port: 6363});
face = new ndn.Face(new ndn.TcpTransport(), new ndn.TcpTransport.ConnectionInfo("hobo.cs.arizona.edu", 9696));
face = new ndn.Face(new ndn.UnixTransport(), new ndn.UnixTransport.ConnectionInfo("/run/nfd.sock"));
face = new ndn.Face(new ndn.WebSocketTransport(), new ndn.WebSocketTransport.ConnectionInfo("hobo.cs.arizona.edu", 9696));
function testBlob() {
let blob = new ndn.Blob();
blob = new ndn.Blob(blob);
blob = new ndn.Blob(Buffer.alloc(4));
blob = new ndn.Blob("str");
let n: number = blob.size();
let buf: Buffer = blob.buf();
let b: boolean = blob.equals(blob);
let s: string = blob.toHex();
s = blob.toString();
b = blob.isNull();
let sb = new ndn.SignedBlob();
sb = new ndn.SignedBlob(sb, 20, 40);
n = sb.signedSize();
buf = sb.signedBuf();
n = sb.getSignedPortionBeginOffset();
n = sb.getSignedPortionEndOffset();
}
function testFaceTransport() {
let face = new ndn.Face();
face = new ndn.Face({host: 'hobo.cs.arizona.edu', port: 6363});
face = new ndn.Face(new ndn.TcpTransport(), new ndn.TcpTransport.ConnectionInfo("hobo.cs.arizona.edu", 9696));
face = new ndn.Face(new ndn.UnixTransport(), new ndn.UnixTransport.ConnectionInfo("/run/nfd.sock"));
face = new ndn.Face(new ndn.WebSocketTransport(), new ndn.WebSocketTransport.ConnectionInfo("hobo.cs.arizona.edu", 9696));
}