• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala Buffer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中io.scalajs.nodejs.buffer.Buffer的典型用法代码示例。如果您正苦于以下问题:Scala Buffer类的具体用法?Scala Buffer怎么用?Scala Buffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Buffer类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: BrakeTest

//设置package包名称以及导入依赖的类
package io.scalajs.npm.brake

import io.scalajs.nodejs.buffer.Buffer
import io.scalajs.nodejs.process
import io.scalajs.npm.readablestream.Readable
import org.scalatest.FunSpec

/**
  * Brake Test
  * @author [email protected]
  */
class BrakeTest extends FunSpec {

  describe("Brake") {

    it("supports throttling streams") {
      val bulk = new Readable()
      bulk._read = () => {}

      ('A' to 'F') foreach { ch =>
        bulk.push(Buffer.from(String.valueOf(ch)))
      }
      bulk.push(null)
      bulk.pipe(Brake(10)).pipe(process.stdout)
    }

  }

} 
开发者ID:scalajs-io,项目名称:brake,代码行数:30,代码来源:BrakeTest.scala


示例2: MemoryFSExtensions

//设置package包名称以及导入依赖的类
package io.scalajs.npm

import io.scalajs.nodejs.buffer.Buffer
import io.scalajs.nodejs.fs.{FileIOError, Stats}
import io.scalajs.util.PromiseHelper._

import scala.concurrent.Future
import scala.scalajs.js
import scala.scalajs.js.Array


  final implicit class MemoryFSExtensions(val fs: MemoryFs) extends AnyVal {

    @inline
    def existsFuture(path: String): Future[Boolean] = promiseWithError1[FileIOError, Boolean](fs.exists(path, _))

    @inline
    def mkdirpFuture(path: String): Future[Unit] = promiseWithError0[FileIOError](fs.mkdirp(path, _))

    @inline
    def readdirFuture(path: String): Future[Array[String]] = {
      promiseWithError1[FileIOError, js.Array[String]](fs.readdir(path, _))
    }

    @inline
    def readFileFuture(path: String, optArg: js.Any = null): Future[Buffer] = {
      promiseWithError1[FileIOError, Buffer](fs.readFile(path, optArg, _))
    }

    @inline
    def rmdirFuture(path: String): Future[Unit] = promiseWithError0[FileIOError](fs.rmdir(path, _))

    @inline
    def statFuture(path: String): Future[Stats] = promiseWithError1[FileIOError, Stats](fs.stat(path, _))

    @inline
    def unlinkFuture(path: String): Future[Unit] = promiseWithError0[FileIOError](fs.unlink(path, _))

    @inline
    def writeFileFuture(path: String, content: String, encoding: String = null): Future[Unit] = {
      promiseWithError0[FileIOError](fs.writeFile(path, content, encoding, _))
    }

    @inline
    def writeFileFuture(path: String, content: Buffer): Future[Unit] = {
      promiseWithError0[FileIOError](fs.writeFile(path, content, _))
    }

  }

} 
开发者ID:scalajs-io,项目名称:memory-fs,代码行数:52,代码来源:package.scala


示例3: PeerId

//设置package包名称以及导入依赖的类
package eu.devtty.peerid

import io.scalajs.nodejs.buffer.Buffer

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@js.native
@JSImport("peer-id", JSImport.Namespace)
class PeerId extends js.Object {
  def toHexString: String = js.native
  def toBytes: Buffer = js.native
  def toB58String: String = js.native

  def toJSON: PeerIdObject = js.native
  def toPrint: PeerIdObject = js.native

  def inEqual(id: PeerId): Boolean = js.native
  def inEqual(id: Buffer): Boolean = js.native
}

@js.native
trait PeerIdObject extends js.Object {
  
  val privKey: String = js.native
} 
开发者ID:magik6k,项目名称:scalajs-ipfs-api,代码行数:27,代码来源:PeerId.scala


示例4: get

//设置package包名称以及导入依赖的类
package eu.devtty.ipfs

import io.scalajs.nodejs.buffer.Buffer
import io.scalajs.nodejs.stream.{Readable, Transform}

import scala.concurrent.Future
import scala.scalajs.js


trait FilesApi {
  
  def get(multihash: String): Future[Readable]

}

object NamedBuffer {
  //TODO: maybe: implicit converter from Seq[(String, Buffer)]
  def apply(path: String, content: Buffer): NamedBuffer =
    js.Dynamic.literal(path = path, content = content).asInstanceOf[NamedBuffer]
}

@js.native
trait NamedBuffer extends js.Object {
  val path: String = js.native
  val content: Buffer = js.native
}

object NamedReadable {
  //TODO: maybe: implicit converter from Seq[(String, Readable)]
  def apply(path: String, content: Readable): NamedReadable =
    js.Dynamic.literal(path = path, content = content).asInstanceOf[NamedReadable]
}

@js.native
trait NamedReadable extends js.Object {
  val path: String = js.native
  val content: Readable = js.native
}

@js.native
trait AddResult extends js.Object {
  val path: String = js.native
  val hash: String = js.native
  val size: Int = js.native //TODO: Long? caused problems somewhere else, need testing
}

@js.native
trait AddStream extends Transform {
  def write(file: NamedBuffer): Unit = js.native
  def write(file: NamedReadable): Unit = js.native
} 
开发者ID:magik6k,项目名称:scalajs-ipfs-api,代码行数:52,代码来源:FilesApi.scala


示例5: peers

//设置package包名称以及导入依赖的类
package eu.devtty.ipfs

import io.scalajs.nodejs.buffer.Buffer

import scala.concurrent.Future
import scala.scalajs.js

trait PubsubApi {
  
  def peers(topic: String): Future[Array[String]]

}

@js.native
trait PubsubMsg extends js.Object {
  val from: String = js.native
  val seqno: Buffer = js.native
  val data: Buffer = js.native
  val topicCIDs: Array[String] = js.native
}

@js.native
trait PubsubSubOpts extends js.Object {
  val discover: Boolean = js.native
} 
开发者ID:magik6k,项目名称:scalajs-ipfs-api,代码行数:26,代码来源:PubsubApi.scala


示例6: stat

//设置package包名称以及导入依赖的类
package eu.devtty.ipfs

import eu.devtty.cid.CID
import io.scalajs.nodejs.buffer.Buffer

import scala.concurrent.Future
import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

trait BlockApi {
  
  def stat(cid: Buffer): Future[BlockStat]
}

@js.native
trait BlockStat extends js.Object {
  val key: String = js.native
  val size: Int = js.native //Long appears to be broken by scalajs, may need some deeper lok
}

@js.native
@JSImport("ipfs-block", JSImport.Namespace)
class Block(val data: Buffer, val cid: CID) extends js.Object

@js.native
@JSImport("ipfs-block", JSImport.Namespace)
object Block extends js.Object {
  def isBlock(other: js.Any): Boolean = js.native
} 
开发者ID:magik6k,项目名称:scalajs-ipfs-api,代码行数:30,代码来源:BlockApi.scala


示例7: JsPubsubApi

//设置package包名称以及导入依赖的类
package eu.devtty.ipfs.jsinterface

import eu.devtty.ipfs.{PubsubApi, PubsubMsg, PubsubSubOpts}
import io.scalajs.nodejs.buffer.Buffer

import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global

class JsPubsubApi(implicit val node: raw.JsIpfsInterface) extends PubsubApi {
  @inline
  private def pubsub = node.pubsub

  def subscribe(topic: String, options: PubsubSubOpts, handler: (PubsubMsg) => Unit): Future[_] = pubsub.subscribe(topic, options, handler).toFuture
  def subscribe(topic: String, handler: (PubsubMsg) => Unit): Future[_] = pubsub.subscribe(topic, handler).toFuture

  def unsubscribe(topic: String, handler: (PubsubMsg) => Unit): Unit = pubsub.unsubscribe(topic, handler)
  def publish(topic: String, data: Buffer): Future[_] = pubsub.publish(topic, data).toFuture
  def ls(topic: String): Future[Array[String]] = pubsub.ls(topic).toFuture.map(_.toArray)
  def ls(): Future[Array[String]] = pubsub.ls().toFuture.map(_.toArray)
  def peers(topic: String): Future[Array[String]] = pubsub.peers(topic).toFuture.map(_.toArray)
} 
开发者ID:magik6k,项目名称:scalajs-ipfs-api,代码行数:22,代码来源:JsPubsubApi.scala


示例8: JsFilesApi

//设置package包名称以及导入依赖的类
package eu.devtty.ipfs.jsinterface

import eu.devtty.ipfs._
import eu.devtty.ipfs.jsinterface.util.FutureCallErr1
import io.scalajs.nodejs.buffer.Buffer
import io.scalajs.nodejs.stream

import scala.concurrent.Future

class JsFilesApi(implicit val node: raw.JsIpfsInterface) extends FilesApi {
  @inline
  private def files = node.files

  def add(data: Array[NamedBuffer], options: DagImporterOptions): Future[Array[AddResult]] = FutureCallErr1(cb => files.add(data, options, { (e,d) => cb(e, d.toArray)}))
  def add(data: Array[NamedReadable], options: DagImporterOptions): Future[Array[AddResult]] = FutureCallErr1(cb => files.add(data, options, { (e,d) => cb(e, d.toArray)}))
  def add(data: Buffer, options: DagImporterOptions): Future[Array[AddResult]] = FutureCallErr1(cb => files.add(data, options, { (e,d) => cb(e, d.toArray)}))
  def add(data: stream.Readable, options: DagImporterOptions): Future[Array[AddResult]] = FutureCallErr1(cb => files.add(data, options, { (e,d) => cb(e, d.toArray)}))

  def add(data: Array[NamedBuffer]): Future[Array[AddResult]] = FutureCallErr1(cb => files.add(data, { (e,d) => cb(e, d.toArray)}))
  def add(data: Array[NamedReadable]): Future[Array[AddResult]] = FutureCallErr1(cb => files.add(data, { (e,d) => cb(e, d.toArray)}))
  def add(data: Buffer): Future[Array[AddResult]] = FutureCallErr1(cb => files.add(data, { (e,d) => cb(e, d.toArray)}))
  def add(data: stream.Readable): Future[Array[AddResult]] = FutureCallErr1(cb => files.add(data, { (e,d) => cb(e, d.toArray)}))


  def createAddStream(options: DagImporterOptions): Future[AddStream] = FutureCallErr1(cb => files.createAddStream(options, cb))

  def cat(multihash: Buffer): Future[stream.Readable] = files.cat(multihash).toFuture
  def cat(multihash: String): Future[stream.Readable] = files.cat(multihash).toFuture
  def get(multihash: Buffer): Future[stream.Readable] = files.get(multihash).toFuture
  def get(multihash: String): Future[stream.Readable] = files.get(multihash).toFuture
} 
开发者ID:magik6k,项目名称:scalajs-ipfs-api,代码行数:32,代码来源:JsFilesApi.scala


示例9: JsBlockApi

//设置package包名称以及导入依赖的类
package eu.devtty.ipfs.jsinterface

import eu.devtty.cid.CID
import eu.devtty.ipfs.jsinterface.util.FutureCallErr1
import eu.devtty.ipfs.{Block, BlockApi, BlockStat}
import io.scalajs.nodejs.buffer.Buffer

import scala.concurrent.Future

class JsBlockApi(implicit val node: raw.JsIpfsInterface) extends BlockApi {
  @inline
  private def block = node.block

  def get(cid: CID): Future[Block] = FutureCallErr1(cb => block.get(cid, cb))
  def get(cid: String): Future[Block] = FutureCallErr1(cb => block.get(cid, cb))
  def get(cid: Buffer): Future[Block] = FutureCallErr1(cb => block.get(cid, cb))

  def put(data: Block): Future[Block] = FutureCallErr1(cb => block.put(data, cb))
  def put(data: Buffer): Future[Block] = FutureCallErr1(cb => block.put(data, cb))

  def stat(cid: CID): Future[BlockStat] = FutureCallErr1(cb => block.stat(cid, cb))
  def stat(cid: String): Future[BlockStat] = FutureCallErr1(cb => block.stat(cid, cb))
  def stat(cid: Buffer): Future[BlockStat] = FutureCallErr1(cb => block.stat(cid, cb))
} 
开发者ID:magik6k,项目名称:scalajs-ipfs-api,代码行数:25,代码来源:JsBlockApi.scala


示例10: subscribe

//设置package包名称以及导入依赖的类
package eu.devtty.ipfs.jsinterface.raw

import eu.devtty.ipfs.{PubsubMsg, PubsubSubOpts}
import io.scalajs.nodejs.buffer.Buffer

import scala.scalajs.js

@js.native
trait JsPubsubApi extends js.Object {
  def subscribe(topic: String, options: PubsubSubOpts, handler: js.Function1[PubsubMsg, Unit]): js.Promise[_] = js.native
  def subscribe(topic: String, handler: js.Function1[PubsubMsg, Unit]): js.Promise[_] = js.native

  def unsubscribe(topic: String, handler: js.Function1[PubsubMsg, Unit]): Unit = js.native

  def publish(topic: String, data: Buffer): js.Promise[_] = js.native
  def ls(topic: String): js.Promise[js.Array[String]] = js.native
  def ls(): js.Promise[js.Array[String]] = js.native
  def peers(topic: String): js.Promise[js.Array[String]] = js.native
} 
开发者ID:magik6k,项目名称:scalajs-ipfs-api,代码行数:20,代码来源:JsPubsubApi.scala


示例11: add

//设置package包名称以及导入依赖的类
package eu.devtty.ipfs.jsinterface.raw

import eu.devtty.ipfs._
import io.scalajs.nodejs.buffer.Buffer
import io.scalajs.nodejs.stream

import scala.scalajs.js
import scala.scalajs.js.Promise

@js.native
trait JsFilesApi extends js.Object {
  def add(data: Array[NamedBuffer], options: DagImporterOptions, callback: js.Function2[String, js.Array[AddResult], _]): Unit = js.native
  def add(data: Array[NamedReadable], options: DagImporterOptions, callback: js.Function2[String, js.Array[AddResult], _]): Unit = js.native
  def add(data: Buffer, options: DagImporterOptions, callback: js.Function2[String, js.Array[AddResult], _]): Unit = js.native
  def add(data: stream.Readable, options: DagImporterOptions, callback: js.Function2[String, js.Array[AddResult], _]): Unit = js.native
  def add(data: Array[NamedBuffer], callback: js.Function2[String, js.Array[AddResult], _]): Unit = js.native
  def add(data: Array[NamedReadable], callback: js.Function2[String, js.Array[AddResult], _]): Unit = js.native
  def add(data: Buffer, callback: js.Function2[String, js.Array[AddResult], _]): Unit = js.native
  def add(data: stream.Readable, callback: js.Function2[String, js.Array[AddResult], _]): Unit = js.native

  def createAddStream(options: DagImporterOptions, callback: js.Function2[String, AddStream, _]): Unit = js.native

  def cat(multihash: Buffer): Promise[stream.Readable] = js.native
  def cat(multihash: String): Promise[stream.Readable] = js.native
  def get(multihash: Buffer): Promise[stream.Readable] = js.native
  def get(multihash: String): Promise[stream.Readable] = js.native
} 
开发者ID:magik6k,项目名称:scalajs-ipfs-api,代码行数:28,代码来源:JsFilesApi.scala


示例12: get

//设置package包名称以及导入依赖的类
package eu.devtty.ipfs.jsinterface.raw

import eu.devtty.cid.CID
import eu.devtty.ipfs.{Block, BlockStat}
import io.scalajs.nodejs.buffer.Buffer

import scala.scalajs.js

@js.native
trait JsBlockApi extends js.Object {
  def get(cid: CID, callback: js.Function2[String, Block, _]): Unit = js.native
  def get(cid: String, callback: js.Function2[String, Block, _]): Unit = js.native
  def get(cid: Buffer, callback: js.Function2[String, Block, _]): Unit = js.native

  def put(block: Block, callback: js.Function2[String, Block, _]): Unit = js.native
  def put(block: Buffer, callback: js.Function2[String, Block, _]): Unit = js.native

  def stat(cid: CID, callback: js.Function2[String, BlockStat, _]): Unit = js.native
  def stat(cid: String, callback: js.Function2[String, BlockStat, _]): Unit = js.native
  def stat(cid: Buffer, callback: js.Function2[String, BlockStat, _]): Unit = js.native
} 
开发者ID:magik6k,项目名称:scalajs-ipfs-api,代码行数:22,代码来源:JsBlockApi.scala


示例13: MultiHash

//设置package包名称以及导入依赖的类
package eu.devtty.multihash

import io.scalajs.nodejs.buffer.Buffer

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@js.native
@JSImport("multihashes", JSImport.Namespace)
object MultiHash extends js.Object {
  
  def validate(multihash: Buffer): Unit = js.native

}

@js.native
trait DecodedMultiHash extends js.Object {
  val code: Int = js.native
  val name: String = js.native
  val length: Int = js.native
  val digest: Buffer = js.native
} 
开发者ID:magik6k,项目名称:scalajs-ipfs-api,代码行数:23,代码来源:Multihash.scala


示例14: MultihashTest

//设置package包名称以及导入依赖的类
package eu.devtty.multihash

import io.scalajs.nodejs.buffer.Buffer
import utest._
import utest.framework.{Test, Tree}

object MultihashTest extends TestSuite {
  override val tests: Tree[Test] = this {
    'MultihashB58Deserialize{
      val buf = MultiHash.fromB58String("QmejvEPop4D7YUadeGqYWmZxHhLc4JBUCzJJHWMzdcMe2y")
      buf.toHexString ==> "1220f3b0e682d79b8b7a2c216d62ace28c5746a548218c77b556ec932f3a64b914b6"
    }

    'decode{
      val buf = Buffer.from("1220f3b0e682d79b8b7a2c216d62ace28c5746a548218c77b556ec932f3a64b914b6", "hex")
      val decoded = MultiHash.decode(buf)

      decoded.code ==> 18
      decoded.length ==> 32
      decoded.name ==> "sha2-256"
    }
  }
} 
开发者ID:magik6k,项目名称:scalajs-ipfs-api,代码行数:24,代码来源:MultihashTest.scala



注:本文中的io.scalajs.nodejs.buffer.Buffer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala longNumber类代码示例发布时间:2022-05-23
下一篇:
Scala Method类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap