标签: chunking

使用Javascript将文件拆分为块

我正在尝试获取单个文件对象,并按指定的块大小将其拆分为块.在我的示例中,尝试将单个文件拆分为1MB块.所以我想出它需要多少块,然后我试图从'offset'开始切片文件(当前块我在*块大小上),并切掉一个块大小.我的第一个切片正确地以1MB出现,但随后的切片变为0,任何想法为什么?在这里有一个工作的codepen:

http://codepen.io/ngalluzzo/pen/VvpYKz?editors=001[1]

var file = $('#uploadFile')[0].files[0];
  var chunkSize = 1024 * 1024;
  var fileSize = file.size;
  var chunks = Math.ceil(file.size/chunkSize,chunkSize);
  var chunk = 0;

  console.log('file size..',fileSize);
  console.log('chunks...',chunks);

  while (chunk <= chunks) {
      var offset = chunk*chunkSize;
      console.log('current chunk..', chunk);
      console.log('offset...', chunk*chunkSize);
      console.log('file blob from offset...', offset)
      console.log(file.slice(offset,chunkSize));
      chunk++;
  }
Run Code Online (Sandbox Code Playgroud)

javascript file chunking

7
推荐指数
2
解决办法
6245
查看次数

使用带有NLTK |的块标签(而不是NER)在句子中创建关系 NLP

我正在尝试创建自定义块标记并从中提取关系.以下是将我带到级联块树的代码.

grammar = r"""
  NPH: {<DT|JJ|NN.*>+}          # Chunk sequences of DT, JJ, NN
  PPH: {<IN><NP>}               # Chunk prepositions followed by NP
  VPH: {<VB.*><NP|PP|CLAUSE>+$} # Chunk verbs and their arguments
  CLAUSE: {<NP><VP>}           # Chunk NP, VP
  """
cp = nltk.RegexpParser(grammar)
sentence = [("Mary", "NN"), ("saw", "VBD"), ("the", "DT"), ("cat", "NN"),
    ("sit", "VB"), ("on", "IN"), ("the", "DT"), ("mat", "NN")]


chunked = cp.parse(sentence)
Run Code Online (Sandbox Code Playgroud)

输出 -

(S(NPH Mary/NN)锯/ VBD(NPH/DT cat/NN)坐/ VB on/IN(NPH/DT垫/ NN))

现在我尝试使用nltk.sem.extract_rels函数提取NPH标记值与其间的文本之间的关系,但它似乎仅适用于使用ne_chunk函数生成的命名实体.

IN = re.compile(r'.*\bon\b')
for rel in nltk.sem.extract_rels('NPH', 'NPH', chunked,corpus='ieer',pattern = …
Run Code Online (Sandbox Code Playgroud)

python nlp named-entity-recognition chunking nltk

7
推荐指数
1
解决办法
275
查看次数

使用Scala Iterator使用RegEx匹配将大型流(从字符串)分解成多个块,然后对这些块进行操作?

我目前正在使用一种不太像scala的方法来解析大型Unix邮箱文件。我仍在学习该语言,并想挑战自己以寻求更好的方法,但是,我不相信我对使用an可以做什么Iterator以及如何有效使用它有扎实的了解。

我目前正在使用 org.apache.james.mime4j,并且使用org.apache.james.mime4j.mboxiterator.MboxIteratorjava.util.Iterator从文件中获取,因此:

 // registers an implementation of a ContentHandler that
 // allows me to construct an object representing an email
 // using callbacks
 val handler: ContentHandler = new MyHandler();

 // creates a parser that parses a SINGLE email from a given InputStream
 val parser: MimeStreamParser = new MimeStreamParser(configBuilder.build());
 // register my handler
 parser.setContentHandler(handler);

 // Get a java.util.Iterator
 val iterator = MboxIterator.fromFile(fileName).build();
 // For each email, process it using above Handler
 iterator.forEach(p => …
Run Code Online (Sandbox Code Playgroud)

regex iterator scala stream chunking

7
推荐指数
1
解决办法
246
查看次数

如何将大文件直接下载到磁盘,而不将其存储在服务器和浏览器的 RAM 中?

我想从我的应用程序使用 Node.js 和 Express.js 运行的同一服务器(没有外部云文件存储,也就是本地)实现一个大文件下载(大约 10-1024 Mb)。

我想通了如何将整个文件转换为做到这一点Blob,通过网络传输,然后生成一个下载链接window.URL.createObjectURL(…)Blob。只要文件很小,这种方法就可以完美地工作,否则不可能将整个文件保存在Blob服务器或客户端的 RAM 中。

我尝试使用File APIAJAX实现其他几种方法,但看起来 Chrome 将整个文件加载到 RAM 中,然后才将其转储到磁盘。同样,对于小文件可能没问题,但对于大文件则不是一种选择。

我的最后一次尝试是发送一个基本的请求Get

const aTag = document.createElement("a");
aTag.href = `/downloadDocument?fileUUID=${fileName}`;
aTag.download = fileName;
aTag.click();
Run Code Online (Sandbox Code Playgroud)

在服务器端:

应用程序.mjs

app.get("/downloadDocument", async (req, res) => {

    req.headers.range = "bytes=0";

    const [urlPrefix, fileUUID] = req.url.split("/downloadDocument?fileUUID=");

    const downloadResult = await StorageDriver.fileDownload(fileUUID, req, res);

});
Run Code Online (Sandbox Code Playgroud)

存储驱动程序

export const fileDownload = async function fileDownload(fileUUID, req, res) {

    //e.g. C:\Users\User\Projects\POC\assets\wanted_file.pdf
    const …
Run Code Online (Sandbox Code Playgroud)

javascript data-transfer download chunking node.js

7
推荐指数
1
解决办法
515
查看次数

序列的F#array_chunk

我在制作序列时遇到了一些麻烦.基本上我需要将序列切割成一系列数组.Seq.windowed几乎做到了,但我不想要重复的元素.

我可以通过首先将所有内容读入数组来获得我想要的内容,但我宁愿使用序列.

let array_chunk s (a:int[]) =
    Array.init (a.Length / s) (fun i -> Array.sub a (i * s) s)

someSequence |> Seq.to_array |> array_chunk 5
Run Code Online (Sandbox Code Playgroud)

arrays f# sequence chunking

6
推荐指数
3
解决办法
1837
查看次数

python:是否有用于分块输入流的库函数?

我想将输入流分块以进行批处理.给定输入列表或生成器,

x_in = [1, 2, 3, 4, 5, 6 ...]
Run Code Online (Sandbox Code Playgroud)

我想要一个返回该输入块的函数.说,如果chunk_size=4,那么,

x_chunked = [[1, 2, 3, 4], [5, 6, ...], ...]
Run Code Online (Sandbox Code Playgroud)

这是我一遍又一遍地做的事情,并且想知道是否有比我自己写的更标准的方式.我错过了什么itertools吗?(人们可以用enumerate和解决问题groupby,但是感觉很笨.)如果有人想要看到一个实现,这里是,

def chunk_input_stream(input_stream, chunk_size):
    """partition a generator in a streaming fashion"""
    assert chunk_size >= 1
    accumulator = []
    for x in input_stream:
        accumulator.append(x)
        if len(accumulator) == chunk_size:
            yield accumulator
            accumulator = []
    if accumulator:
        yield accumulator
Run Code Online (Sandbox Code Playgroud)

编辑

灵感来自kreativitea的答案,这是一个解决方案islice,它很简单,不需要后置过滤,

from itertools import islice

def chunk_input_stream(input_stream, chunk_size):
    while True:
        chunk = …
Run Code Online (Sandbox Code Playgroud)

python stream chunking python-itertools

6
推荐指数
2
解决办法
1231
查看次数

以块的形式下载文件(Windows Phone)

在我的应用程序中,我可以从网上下载一些媒体文件.通常我使用WebClient.OpenReadCompleted方法下载,解密并将文件保存到IsolatedStorage.它运作良好,看起来像这样:

 private void downloadedSong_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e, SomeOtherValues someOtherValues) // delegate, uses additional values
        {
            // Some preparations

                try
                {
                   if (e.Result != null)
                   {
                    using (isolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication())
                    {
                        // working with the gained stream, decryption
                        // saving the decrypted file to isolatedStorage
                        isolatedStorageFileStream = new IsolatedStorageFileStream("SomeFileNameHere", FileMode.OpenOrCreate, isolatedStorageFile);
                        // and use it for MediaElement
                        mediaElement.SetSource(isolatedStorageFileStream);
                        mediaElement.Position = new TimeSpan(0);
                        mediaElement.MediaOpened += new RoutedEventHandler(mediaFile_MediaOpened);

                        // and some other work
                     }
                    }
                 }
                 catch(Exception ex) 
                 {
                  // try/catch …
Run Code Online (Sandbox Code Playgroud)

c# download chunking windows-phone-7

6
推荐指数
1
解决办法
2407
查看次数

懒惰不能按预期工作

(defn seq-trial
  []
  (map #(do (println "hello " %) (inc %)) (range 10)))

(take 3 (seq-trial))
Run Code Online (Sandbox Code Playgroud)

评估时上面的代码snippt打印出以下内容 -

(你好0你好1你好2你好3你好4 hello 5你好6 hello 7你好8你好9 1 2 3)

因为map返回了一个懒惰的序列,我希望这只能打印 -

(你好0你好1你好2 1 2 3)

为什么在这里评估整个列表?

functional-programming clojure lazy-evaluation chunking

6
推荐指数
1
解决办法
115
查看次数

通过http post使用块上传大型视频

我想将大型视频从iPhone上传到网络服务器.我试过下面的代码.它适用于小文件,但当我尝试上传大文件时,它会崩溃.

码:

NSMutableURLRequest *request = [NSMutableURLRequest
                                requestWithURL:[NSURL URLWithString:@"https://XXXXXXXXXXXXXXXX/submit.php"]];

NSData *webData = [NSData dataWithContentsOfURL:movieUrl];
NSString *postLength = [NSString stringWithFormat:@"%d", [webData length]];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];

---- added some HTTP headers here ----

[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];

NSMutableData *postbody = [NSMutableData data];
[postbody appendData:[NSData dataWithData:webData]];
[request setHTTPBody:postbody];

NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
Run Code Online (Sandbox Code Playgroud)

经过研究我得到了一个想法,如果我在大块数据中发送大文件,这将是可能的.solution1,solution2.

我还经历了Stream Programming apple doc. 但不知道在哪里定义服务器NSURL.将数据写入输出流后如何发送到服务器.

如果有人能指出我的任何工作代码,那么我将能够更好地理解它.

怎么做?有什么想法吗?

file-upload http chunking ipad ios

6
推荐指数
0
解决办法
3687
查看次数

Play 2.2中的慢块响应

在我的基于Play框架的Web应用程序中,用户可以以csv或json格式下载不同数据库表的所有行.表格相对较大(100k +行),我试图使用Play 2.2中的分块来回传结果.

但问题是虽然println语句显示行被写入Chunks.Out对象,但它们不会显示在客户端!如果我限制发回的行将会起作用,但是如果我尝试发送所有行并导致超时或服务器内存不足,那么它在开始时也会有很大的延迟.

我使用Ebean ORM并且表被索引并且从psql查询不需要花费太多时间.有谁知道可能是什么问题?

我非常感谢你的帮助!

以下是其中一个控制器的代码:

@SecureSocial.UserAwareAction
public static Result showEpex() {

    User user = getUser();
    if(user == null || user.getRole() == null)
        return ok(views.html.profile.render(user, Application.NOT_CONFIRMED_MSG));

    DynamicForm form = DynamicForm.form().bindFromRequest();
    final UserRequest req = UserRequest.getRequest(form);

    if(req.getFormat().equalsIgnoreCase("html")) {
        Page<EpexEntry> page = EpexEntry.page(req.getStart(), req.getFinish(), req.getPage());
        return ok(views.html.epex.render(page, req));
    }

    // otherwise chunk result and send back
    final ResultStreamer<EpexEntry> streamer = new ResultStreamer<EpexEntry>();
    Chunks<String> chunks = new StringChunks() {
            @Override
            public void onReady(play.mvc.Results.Chunks.Out<String> out) {

                Page<EpexEntry> page = EpexEntry.page(req.getStart(), req.getFinish(), 0); …
Run Code Online (Sandbox Code Playgroud)

java chunking ebean playframework-2.0

6
推荐指数
1
解决办法
1608
查看次数